How to move a file that has no file extension? C#

后端 未结 3 1898
你的背包
你的背包 2021-01-23 04:52
if (File.Exists(@\"C:\\\\Users\" + Environment.UserName + \"\\\\Desktop\\\\test\"))
{                                                                /\\
                         


        
3条回答
  •  长发绾君心
    2021-01-23 05:44

    Having no extension has no bearing on the function. Also, a rename is really just a move "in disguise", so what you want to do is

    File.Move(@"C:\Users\Username\Desktop\test", @"C:\Users\Username\Desktop\potato.txt")
    

    Please bear in mind the @ before the string, as you haven't escaped the backslashes.

提交回复
热议问题