C# 在不指定路径的情况下移动文件
C# Moved file without specifying path
我刚刚运行
File.Move(@"C:\sub1\file.xml", "file" + ".XMl"));
文件确实从 C:\sub1
中消失了。没有抛出错误。文件去了哪里?
是的,它在您的 运行 文件夹中。
它移动到应用程序工作目录。通常是可执行文件所在的位置
当目录未指定时,当前使用一个:
https://msdn.microsoft.com/en-us/library/system.io.file.move(v=vs.110).aspx
The sourceFileName and destFileName arguments can include relative or
absolute path information. Relative path information is interpreted as
relative to the current working directory. To obtain the current
working directory, see GetCurrentDirectory.
Environment.CurrentDirectory = @"C:\Test";
// C:\sub1\file.xml will be moved to C:\Test\file.XMl
File.Move(@"C:\sub1\file.xml", "file" + ".XMl"));
我刚刚运行
File.Move(@"C:\sub1\file.xml", "file" + ".XMl"));
文件确实从 C:\sub1
中消失了。没有抛出错误。文件去了哪里?
是的,它在您的 运行 文件夹中。
它移动到应用程序工作目录。通常是可执行文件所在的位置
当目录未指定时,当前使用一个:
https://msdn.microsoft.com/en-us/library/system.io.file.move(v=vs.110).aspx
The sourceFileName and destFileName arguments can include relative or absolute path information. Relative path information is interpreted as relative to the current working directory. To obtain the current working directory, see GetCurrentDirectory.
Environment.CurrentDirectory = @"C:\Test";
// C:\sub1\file.xml will be moved to C:\Test\file.XMl
File.Move(@"C:\sub1\file.xml", "file" + ".XMl"));