档测试没有扩展名,我需要帮助来移动或用此文件的东西与扩展如何检查文件是否存在文件扩展名? C#
if(File.Exists(@"C:\\Users" + Environment.UserName + "\\Desktop\\test"))
{ /\
this file has no file extension
}
档测试没有扩展名,我需要帮助来移动或用此文件的东西与扩展如何检查文件是否存在文件扩展名? C#
if(File.Exists(@"C:\\Users" + Environment.UserName + "\\Desktop\\test"))
{ /\
this file has no file extension
}
重命名试试这样:
DirectoryInfo d = new DirectoryInfo("directory path");
FileInfo[] f = d.GetFiles("test.*");
if (f.Length > 0)
{
File.Move(oldPath, newPath);
}
else
{
//File does not exist
}
“试试这个”不是一个答案。你也没有试图理解OP的问题,你只是回答了标题。 – CodeCaster
使用目录信息获取目录中的文件列表,然后对于没有扩展名的文件,将其删除。
我创建了一个名为test
的文件,在文件夹M:\Incoming
中没有扩展名。
运行下面的代码在这两种情况下工作:
if (File.Exists(@"M:\Incoming\test"))
Console.WriteLine("Exists");
if (File.Exists(@"M:\\Incoming\\test"))
Console.WriteLine("Exists");
当使用@
你不需要指定两条斜线,虽然它没有什么区别反正在这个例子中。
输出:
已存在
已存在
你的问题是最有可能是在你所串联的字符串的方式。
您忘记了''C:\\ Users“' – xanatos
之后的'\\'此外,使用@”“时,您不需要双重转义反斜杠。 – LInsoDeTeh
不要发布重复问题 – Paparazzi