我在“D:\TestField”中有三个文件夹。它们是“备份”、“ExampleFileUpdatePrimary”、“ExampleFileUpdateSecondary.zip”。我可以删除“D:\TestField\ExampleFileUpdatePrimary”文件夹,但不能删除“D:\TestField\ExampleFileUpdateSecondary.zip”
我的子函数是;
Private Sub DeleteFolder(ByVal path As String)
path = path.Remove(path.Length - 1) 'D:\TestField\ExampleFileUpdatePrimary
Dim path2 = path & ".zip" 'D:\TestField\ExampleFileUpdateSecondary.zip
My.Computer.FileSystem.DeleteDirectory(path, FileIO.DeleteDirectoryOption.DeleteAllContents) 'its working
'Dim di = New IO.DirectoryInfo(path2) 'try1
'di.Delete(True)
'IO.Directory.Delete(path2) 'try2
'My.Computer.FileSystem.DeleteDirectory(path2, FileIO.DeleteDirectoryOption.DeleteAllContents) 'try3
End Sub
try1,try2 异常说“目录名无效”
try3 异常显示“System.IO.DirectoryNotFoundException: ''D:\TestField\ExampleFileUpdateSecondary.zip”
我找不到新的解决方案或尝试删除代码中的 .zip 文件
谢谢