Movinf files to recycle bin

G

Guest

Hello, I want to achieve a few things with this code (below), but of course
it doesn't work. I did suspect it wouldn't be long before I posted a question!

If I take out the "If" and "For" it DOES delete the file, but I want it to
go to the Recycle Bin, and deleteFile seems to kill it completely.

Next, I want to loop through the client's folder and only delete certain
filenames (hence the if and For). When I have this part right I'll probably
wrap it in a Do loop to cycle through the various filenames. In the meantime
could some please help with the Recycle Bin, If and For part?

Regards, Brett

Sub aaDELETE_FILES_FROM_FOLDER()
surname = "surname"
initial = "I"
clientfolder = "C:\1. ACTIVE CLIENTS\" & surname & ", " & initial
clientfile = clientfolder & "\" & "2. NSC " & surname & ".xls"
Set fso = CreateObject("scripting.FileSystemObject")
For Each file In clientfolder.Files
If file.Path = clientfolder & "\" & "2. NSC " & surname & ".xls" Then
fso.deleteFile clientfile
On Error GoTo 0
End If
Next file

End Sub
 

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

Similar Threads

Recycle bin problems 5
Recycle bin 8
If not in "Recycle Bin " then where? 1
Can't Delete Corrupt Recycle Bin 4
Recycle Bin problem 1
Recycle Bin path 1
files not going to recycle bin 6
Recycle Bin Restoring 4

Top