VBA to empty network folder

rvsebi

Registered User.
Local time
Today, 17:03
Joined
Jun 1, 2015
Messages
77
Hi,
I need to empty some network folder with vba, first i tried with vbs;
Code:
Set fso = CreateObject("Scripting.FileSystemObject")
Set folder = fso.GetFolder("\\192.168.4.245\Recycle Bin - Volume_1")
' delete all subfolders and files
For Each f In folder.SubFolders
   On Error Resume Next
   name = f.name
   f.Delete True
   If Err Then
     WScript.Echo "Error deleting:" & Name & " - " & Err.Description
   Else
     ''WScript.Echo "Deleted:" & Name
   End If
   On Error GoTo 0
Next

but is not working.
Please help me!
Thank you!
 
You aren't declaring or setting a value for f .

I also believe you have to delete the files in the sub folder before you can delete the folder.
 
This MIGHT be a case where a command-line operation via the SHELL option would be better. You might wish to execute a command such as

Code:
C:>DEL /S /Q \\192.168.4.245\Recycle Bin - Volume_1\*.*

/S is "do it for subdirectories, too"
/Q is "do it quietly"

You can look up using SHELL commands from this forum's search options or from the great Google brain. I'm saying it might be easier because it is a single-line command. However, it will depend on the access rights you have to the network folder in question.
 
Thank you for answers.
I did it with cmd files;
Code:
robocopy "\\192.168.4.245\personal\emptyrecyclebin\empty" "\\192.168.4.245\Recycle Bin - Volume_1" /purge
 
Probably a better choice doing it wholesale than trying to do it piecemeal through the file system object. At least, easier. And you could issue that command through the SHELL command so Access can still trigger it.
 

Users who are viewing this thread

Back
Top Bottom