Rename some files in a folder

前端 未结 6 822
遇见更好的自我
遇见更好的自我 2020-12-05 05:59

I have a task of changing the names of some files (that is, adding id to each name dynamically) in a folder using C#.

Example: help.txt to 1help.txt

How can

6条回答
  •  星月不相逢
    2020-12-05 06:48

    You can use File.Move, like this:

    string oldFilePath = Path.Combine( Server.MapPath("~/uploads"), "oldFileName");
    string newFilePath = Path.Combine( Server.MapPath("~/uploads"), "newFileName");
    
    File.Move(oldFilePath, newFilePath);
    

提交回复
热议问题