List File size

Khan kashaf

New Member
Joined
May 11, 2021
Messages
14
Office Version
  1. 2019
  2. 2016
  3. 2010
Platform
  1. Windows
  2. MacOS
  3. Mobile
  4. Web
Create a list of all files in a given folder which are more than 50KB in size - display the list in excel
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
I found this several years ago and original author is unknown. You can modify as needed.

Code:
Sub GetFiles()
Dim RowNumber As Long
Range("A1").Value = File
strFolder = ActiveWorkbook.Path
Set fso = CreateObject("Scripting.FileSystemObject")
Set folder = fso.GetFolder(strFolder)

RowNumber = RowNumber + 1

Call GetSubFolderSize(strFolder + "\")
End Sub

Sub GetSubFolderSize(strFolder)
a = Cells(Rows.Count, 2).End(xlUp).Row + 1
Set fso = CreateObject("Scripting.FileSystemObject")

Set folder = fso.GetFolder(strFolder)

If folder.subfolders.Count > 0 Then
For Each sf In folder.subfolders
On Error GoTo 100
Call GetSubFolderSize(strFolder + sf.Name + "\")
100 Next sf
End If
'folder size in bytes
On Error GoTo 200

For Each MyFile In folder.Files
Range("B" & a + 1).Value = MyFile.Path
Range("A" & a + 1).Value = MyFile.Size / 1024 ^ 2
' or remove the division for size
Range("C" & a + 1).Value = MyFile.Datelastmodified
a = a + 1
Next MyFile
200 On Error GoTo 0
End Sub
 
Upvote 0
I found this several years ago and original author is unknown. You can modify as needed.

Code:
Sub GetFiles()
Dim RowNumber As Long
Range("A1").Value = File
strFolder = ActiveWorkbook.Path
Set fso = CreateObject("Scripting.FileSystemObject")
Set folder = fso.GetFolder(strFolder)

RowNumber = RowNumber + 1

Call GetSubFolderSize(strFolder + "\")
End Sub

Sub GetSubFolderSize(strFolder)
a = Cells(Rows.Count, 2).End(xlUp).Row + 1
Set fso = CreateObject("Scripting.FileSystemObject")

Set folder = fso.GetFolder(strFolder)

If folder.subfolders.Count > 0 Then
For Each sf In folder.subfolders
On Error GoTo 100
Call GetSubFolderSize(strFolder + sf.Name + "\")
100 Next sf
End If
'folder size in bytes
On Error GoTo 200

For Each MyFile In folder.Files
Range("B" & a + 1).Value = MyFile.Path
Range("A" & a + 1).Value = MyFile.Size / 1024 ^ 2
' or remove the division for size
Range("C" & a + 1).Value = MyFile.Datelastmodified
a = a + 1
Next MyFile
200 On Error GoTo 0
End Sub

I found this several years ago and original author is unknown. You can modify as needed.

Code:
Sub GetFiles()
Dim RowNumber As Long
Range("A1").Value = File
strFolder = ActiveWorkbook.Path
Set fso = CreateObject("Scripting.FileSystemObject")
Set folder = fso.GetFolder(strFolder)

RowNumber = RowNumber + 1

Call GetSubFolderSize(strFolder + "\")
End Sub

Sub GetSubFolderSize(strFolder)
a = Cells(Rows.Count, 2).End(xlUp).Row + 1
Set fso = CreateObject("Scripting.FileSystemObject")

Set folder = fso.GetFolder(strFolder)

If folder.subfolders.Count > 0 Then
For Each sf In folder.subfolders
On Error GoTo 100
Call GetSubFolderSize(strFolder + sf.Name + "\")
100 Next sf
End If
'folder size in bytes
On Error GoTo 200

For Each MyFile In folder.Files
Range("B" & a + 1).Value = MyFile.Path
Range("A" & a + 1).Value = MyFile.Size / 1024 ^ 2
' or remove the division for size
Range("C" & a + 1).Value = MyFile.Datelastmodified
a = a + 1
Next MyFile
200 On Error GoTo 0
End Sub
Thank you so much ✌️
 
Upvote 0

Forum statistics

Threads
1,215,069
Messages
6,122,959
Members
449,096
Latest member
Anshu121

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top