【发布时间】:2015-09-05 07:23:49
【问题描述】:
文件测试没有扩展名,我需要帮助才能将此文件移动或重命名为带有扩展名的文件
if(File.Exists(@"C:\\Users" + Environment.UserName + "\\Desktop\\test"))
{ /\
this file has no file extension
}
【问题讨论】:
-
你忘记了
"C:\\Users"之后的`\\` -
另外,当使用@"" 时,您不需要对反斜杠进行双重转义。
-
不要发布重复的问题
-
使用 System.IO.Path.Combine。还有一种获取桌面目录的推荐方法:Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory)