Find Folder Size

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi Is it possible to find a folder size, and also how can I list duplicate
files into a listbox any help will be much appreciated thanks.
Charles
 
Hi ,

You can use this :
Private Sub UserForm_Activate()
Dim Drv As Scripting.FileSystemObject
Dim Filesx As Scripting.File
Dim SourceFolder As Scripting.Folder

Set Drv = New Scripting.FileSystemObject
Set SourceFolder = Drv.GetFolder("c:\")

' List of files in your c:\ drive
For Each Filesx In SourceFolder.Files
ListBox1.AddItem Filesx.Name
Next Filesx

' List of sizes in your c:\ drive
msg = "Used space: " & _
FormatNumber(Drv.GetDrive("c:\").TotalSize - _
Drv.GetDrive("c:\").FreeSpace, 0)
msg = msg & vbCr & "Free space: " & _
FormatNumber(Drv.GetDrive("c:\").FreeSpace, 0)
msg = msg & vbCr & "Capacity: " & _
FormatNumber(Drv.GetDrive("c:\").TotalSize, 0)

MsgBox msg, vbInformation, "Drive c:\"

End Sub

but before run you have to add your VBA references with
Microsoft Scripting runtime
from Tools>References>
and check "Microsoft Scripting runtime" box
 
Sub FolderSize()
Dim oFSO As Object

Set oFSO = CreateObject("Scripting.FileSystemobject")
MsgBox Format(oFSO.getfolder("C:\myTest").Size, "#,##0 ""bytes""")

Set oFSO = Nothing
End Sub


--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)
 
Thanks!
Can you answer one more question for me is it possible to list up duplicate
files in a userform?.
 
I might if I understood what you meant.

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)
 
I have been asked to show a userform that a user can enter Drive or drive and
subfolder and list in a listbox any duplicated fils.
Regards
Charles
 
Hi,
What you mean with duplicate files?
If all type of files you can use :

Dim mydir
mydir = Dir("C:\*.*")
Do While mydir <> ""
ListBox1.AddItem mydir
mydir = Dir
Loop
 
Doesn't help. What is a duplicated file, the possibilities are endless.

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)
 
Files with the same name.
Regards
Charles

Halim said:
Hi,
What you mean with duplicate files?
If all type of files you can use :

Dim mydir
mydir = Dir("C:\*.*")
Do While mydir <> ""
ListBox1.AddItem mydir
mydir = Dir
Loop

--

Regards,

Halim
 
You mean search the entire drive+root folder or sub folders for files that
have exactly the same name and extension ?

NickHK
 
I would like to give the user a choice of either if possible.
Regards
Charles
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top