C# 我的功能目录有问题。是否删除?
看看我的代码:C# 我的功能目录有问题。是否删除?,c#,C#,看看我的代码: string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); try { if (Directory.Exists(Path.Combine(desktopPath, "Hackers.avi"))) Directory.Delete(Path.Combine(desktopPath, "H
string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
try
{
if (Directory.Exists(Path.Combine(desktopPath, "Hackers.avi")))
Directory.Delete(Path.Combine(desktopPath, "Hackers.avi"), true);
运行后,我的桌面上仍然存在文件,为什么?黑客不太可能
黑客。avi
是一个目录-。avi
通常用作视频文件的扩展名(有关更多信息,请参阅Wikipedia)
尝试使用而不是目录。删除:
string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
try
{
string pathToFile = Path.Combine(desktopPath, "Hackers.avi");
File.Delete(pathToFile);
// etc...
我还省略了对File.Exists
的调用,因为删除文件之前不必检查文件是否存在<代码>文件。如果文件不存在,则删除不会抛出 若要删除文件,则必须使用“file.delete”那么,“Hackers.avi”是文件还是目录?