wonderbread123
asked on
Need to empty folder on script execution...
Hi,
I just need a simple script that when it is run it will EMPTY the contents of a folder, but not delete the folder itself. The folder is "C:\Documents and Settings\User Name\My Documents\temp". Thanks in advance.
I just need a simple script that when it is run it will EMPTY the contents of a folder, but not delete the folder itself. The folder is "C:\Documents and Settings\User Name\My Documents\temp". Thanks in advance.
ASKER
Ok, that works on the files, but it still leaves the folders.
ASKER
The folders INSIDE that folder, that is...
Do you want to remove the subfolders, or just empty them?
S
S
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I want to delete the subfolders.
Where do I set that reference?
Where do I set that reference?
From the menu bar, click Project, select References, and scroll down to Microsoft Scripting Runtime, and check the checkbox on the left.
S
S
ASKER
It works perfectly, thanks alot!
You are welcome, Thanks for the points :)
S
S
Call DeleteFolder("username")
End Sub
Public Sub DeleteFolder(ByVal sbUserName As String)
Dim delFile As String, tmpFolder As String
tmpFolder = Replace("C:\Documents and Settings\User Name\My Documents\temp", "User Name", sbUserName) & "\"
On Error Resume Next
delFile = Dir(tmpFolder & "*.*", vbDirectory)
Do While Not delFile = ""
Select Case delFile
Case ".", ".."
'do nothing
Case Else
Kill tmpFolder & delFile
End Select
delFile = Dir
Loop
MsgBox "Done"
End Sub
S