Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

deleting files in a folder

Status
Not open for further replies.

derwent

Programmer
May 5, 2004
428
GB
I have a folder that is so large that I cannot open it so I wrote a simple .vbs script to wipe the files within it.

Code:
dim fso
dim folder
dim file
dim x
    
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set folder = fso.GetFolder("C:\myfolder")
    
    For Each file In folder.Files
        file.Delete
        x = x + 1
        If x = 100000 Then
            Exit For
        End If
    Next
    x = 0

Is there a way to display it's progress as as the file stands it just does it in the background and we don`t know how it is doing.
 
dim fso
dim folder
dim file
dim x

Set fso = CreateObject("Scripting.FileSystemObject")
Set folder = fso.GetFolder("C:\myfolder")

Dim NumFiles as long

numfiles = 0
For Each file In folder.Files
numfiles = numfiles + 1
Next

For Each file In folder.Files
file.Delete
x = x + 1
if x mod 20 = 0 then
form1.caption = str$(x) & " of " & _ str$(numfiles) & " Files"
end if
If x = 100000 Then
Exit For
End If
Next
x = 0


 
Wouldn't it be easier to just delete the folder and then recreate it?
Code:
    Dim FolderName                  As String
    FolderName = "C:\myFolder"
    With New FileSystemObject
       If .FolderExists(FolderName) Then .DeleteFolder FolderName, True
       .CreateFolder FolderName
    End With
I tried this on a folder with 3000 files occuping 1.6 GB and it took about 10 seconds.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top