How to copy a file to another path?

后端 未结 9 1023
长发绾君心
长发绾君心 2020-11-27 04:59

I need to copy a file to another path, leaving the original where it is.

I also want to be able to rename the file.

Will FileInfo\'s CopyTo method work?

9条回答
  •  再見小時候
    2020-11-27 05:34

    Have a look at File.Copy()

    Using File.Copy you can specify the new file name as part of the destination string.

    So something like

    File.Copy(@"c:\test.txt", @"c:\test\foo.txt");
    

    See also How to: Copy, Delete, and Move Files and Folders (C# Programming Guide)

提交回复
热议问题