Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Excel 2010: Function to acquire file size in bytes

Posted on 2012-03-17
3
258 Views
Last Modified: 2012-03-18
For the purpose of planning play list play times, is there an Excel function to get a file's size in bytes?

For example column A, I list MP3 files by name, for example: (The file in A34)
     E:\Music\PlayList1\The Little River Band - Down On The Border.MP3

Is there an excel function such as "FileSizeOf(A34)"  and return  4022196
     (the actual size of the file in bytes)

TIA - Ed
0
Comment
Question by:Ed Covney
  • 2
3 Comments
 
LVL 42

Accepted Solution

by:
dlmille earned 500 total points
ID: 37734139
Yes, you can do that.  Attached, I wrote your function which you can use like you asked.  I also create a macro to just give you the result on all files in column A (which may be faster/more efficient).

PS - the FileLen() function will provide size in bytes up to 4GB.

Function fileSizeOf(r As Range) As Variant
    On Error Resume Next
    fileSizeOf = FileLen(r.Value)
    On Error GoTo 0
End Function
Sub getFilesizes()
Dim wkb As Workbook
Dim wks As Worksheet
Dim rng As Range
Dim r As Range

    Set wkb = ThisWorkbook
    Set wks = wkb.ActiveSheet
    
    Set rng = wks.Range("A2", wks.Range("A" & wks.Rows.Count).End(xlUp))
    
    For Each r In rng
        r.Offset(, 1).Value = fileSizeOf(r)
    Next r
    
End Sub

Open in new window


See attached demonstration workbook.  Just put your file names  fully pathed in Column A and copy down the formula, or hit the button to just give you the result.

Dave
fileSizeInfo-r1.xls
0
 
LVL 42

Expert Comment

by:dlmille
ID: 37734144
For files of any size you can use this workbook with a function & complimentary macro that returns the file size in GB's instead.  > 4GB would be a very large MP3, but just for completeness, here's that solution ;)

See attached.

Dave
fileSizeInfo-r2.xls
0
 
LVL 2

Author Closing Comment

by:Ed Covney
ID: 37735229
Dave - EXCELLENT !!

Now I just have to figure out how to import your macro into my spreadsheet.
I have lots to learn, thanks for a great start.

Ed
0

Featured Post

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

My experience with Windows 10 over a one year period and suggestions for smooth operation
Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question