visualbasic 无法删除目录中的 .zip 文件
visualbasic cant delete .zip file in a directory
我在“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 文件
谢谢
以 .zip
结尾的目录条目通常是 文件 而不是文件夹,即使 Windows Explorer 将它们显示为文件夹。
因为是文件,所以用File.Delete
代替。
我在“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 文件
谢谢
以 .zip
结尾的目录条目通常是 文件 而不是文件夹,即使 Windows Explorer 将它们显示为文件夹。
因为是文件,所以用File.Delete
代替。