Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Excel 2010: Function to acquire file size in bytes

Posted on 2012-03-17
3
Medium Priority
?
278 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
[X]
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
  • 2
3 Comments
 
LVL 42

Accepted Solution

by:
dlmille earned 2000 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 3

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

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

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

This article describes a serious pitfall that can happen when deleting shapes using VBA.
New style of hardware planning for Microsoft Exchange server.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

610 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