修改文件名字或者将文件移动打新的目录

 1 static void Main(string[] args)
 2 {
 3     //当前工作目录
 4     Console.WriteLine($"CurrentDirectory = {Environment.CurrentDirectory}");
 5 
 6     //原始名字
 7     string oldFullPath = Path.Combine(Environment.CurrentDirectory, "Test.txt");
 8     Console.WriteLine($"path = {oldFullPath}");
 9 
10     //保持目录不变修改名字
11     //string newFullPath = Path.Combine(Environment.CurrentDirectory, "NewTest.txt");
12 
13     //移动到新的目录
14     var parentDir = Directory.GetParent(Environment.CurrentDirectory);
15     string newFullPath = Path.Combine(parentDir.FullName, "NewTest.txt");
16 
17     FileInfo fi = new FileInfo(oldFullPath);
18     fi.MoveTo(newFullPath);
19     Console.ReadKey();
20 }

 

上一篇:SpringBoot的自动装配机制


下一篇:重启winform程序代码