![](/img/trans.png)
[英]How to delete all text in a text file on ftp server without deleting file itself in vb.net
[英]vb.net help, how to skip deleting a file without permission
在 VB.net 上,我正在制作一个文件清理器,它可以删除 temp 等内容,但是对于 prefetch 和 temp 之类的文件夹,当时正在使用一些文件夹,有办法让程序跳过不可删除的文件并清除其他所有内容,谢谢
您应该在按钮单击事件上使用以下代码(需要管理员):
Shell("CLEANMGR", "/d <drive_letter> /sagerun:64")
执行上述代码时,可能会删除以下项目:
使用 CleanMGR 的来源: cleanmgr 命令行开关...
您需要将删除例程包装在 try catch 语句中:
Try
System.IO.File.Delete([FILENAME])
Catch ex as Exception
'Log out to console
Console.WriteLine(ex.Message)
End Try
如果您的目标是编写此实用程序(因此您对重新使用执行相同操作的现有实用程序不感兴趣),那么在尝试之前检查您是否可以删除文件并不是一个好方法。 有些事情您无法测试,即使您可以测试,也无法保证当您尝试删除文件时(即使是很短的时间),该文件将位于同一个 state 中,因此您的操作可能无论如何都会失败。
因此,go 的唯一方法是在每个文件操作周围放置一个Try
/ Catch
(或接受失败可能导致崩溃的可能性)。
生成的伪代码类似于:
For Each (item in top-level list of places to search)
Try
'If directory, try to enter it. If successful, recurse.
'If file, try to delete it.
Catch
'Can log or just skip, this is a valid case to eat an exception
'At a minimum, you might see a System.IO.IOException or a couple of different security-related exceptions
End Try
Next
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.