Reputation: 399
So basically I'd like to know how to do so.
I have no idea how to do so, a macro that'd delete a file or a folder from a ftp folder that's defined in windows (a network folder)
Ty in advance.
Upvotes: 0
Views: 2035
Reputation: 1118
There's a few ways you can do this, but the easiest would probably be with Kill
.
Delete one file
Sub MySub()
Dim myPath as String
myPath = "\\server\Folder\File"
If Dir(myPath) <> "" Then Kill myPath
End Sub
Delete multiple files of the same type
Sub MySub()
Dim myPath as String
myPath = "\\server\Folder\*.xls"
If Dir(myPath) <> "" Then Kill myPath
End Sub
Delete all files in a folder
Sub MySub()
Dim myPath as String
myPath = "\\server\Folder\*.*"
If Dir(myPath) <> "" Then Kill myPath
End Sub
Delete Entire Folder
Sub MySub()
Dim myPath as String
myPath = "\\server\Folder\*.*"
myFolder = "\\server\Folder\"
If Dir(myPath) <> "" Then
Kill myPath
RmDir myFolder 'For RmDir to work, the folder has to be empty
End If
End Sub
There are many more ways to do this, I'm just showing an example with Kill
. You could use FSOs to do all of this as well.
Important: You cannot undo deleting an item like this. This permanently deletes the file. (It doesn't go to the recycle bin, you can't bring files back to life that you've killed.)
Upvotes: 1