使用VBA删除FTP文件夹中的文件和文件夹

时间:2016-09-23 13:23:17

标签: vba excel-vba ftp excel

所以基本上我想知道怎么做。

我不知道怎么做,一个从Windows(网络文件夹)中定义的ftp文件夹中删除文件或文件夹的宏

提前Ty。

1 个答案:

答案 0 :(得分:1)

有几种方法可以做到这一点,但最简单的方法可能是Kill

删除一个文件

Sub MySub()
    Dim myPath as String

    myPath = "\\server\Folder\File"

    If Dir(myPath) <> "" Then Kill myPath
End Sub

删除多个相同类型的文件

Sub MySub()
    Dim myPath as String

    myPath = "\\server\Folder\*.xls"

    If Dir(myPath) <> "" Then Kill myPath
End Sub

删除文件夹中的所有文件

Sub MySub()
    Dim myPath as String

    myPath = "\\server\Folder\*.*"

    If Dir(myPath) <> "" Then Kill myPath
End Sub

删除整个文件夹

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

还有很多方法可以做到这一点,我只是展示Kill的示例。您也可以使用FSO来完成所有这些工作。

重要提示:您无法撤消删除此类项目。这将永久删除该文件。 (它不会进入回收站,您可以将文件恢复到您已经杀死的生活中。)