C# 使用C将文件移动到目录下#
我想移动或复制“D:\”目录下的“efe.txt”文件。我该怎么做呢 感谢您的建议….来自MSDN:: 试一试C# 使用C将文件移动到目录下#,c#,file,copy,directory,move,C#,File,Copy,Directory,Move,我想移动或复制“D:\”目录下的“efe.txt”文件。我该怎么做呢 感谢您的建议….来自MSDN:: 试一试 正如其他人所提到的,您希望使用File.Move,但如果您输入了Path.combined和Path.GetFileName,就像这样 using System.IO; ... string src = "C:\\efe.txt"; string dest = "D:\\efe.txt"; File.Move(src, dest); // Simple synchronous fil
正如其他人所提到的,您希望使用
File.Move
,但如果您输入了Path.combined
和Path.GetFileName
,就像这样
using System.IO;
...
string src = "C:\\efe.txt";
string dest = "D:\\efe.txt";
File.Move(src, dest);
// Simple synchronous file move operations with no user interface.
public class SimpleFileMove
{
static void Main()
{
string sourceFile = @"C:\Users\Public\public\test.txt";
string destinationFile = @"C:\Users\Public\private\test.txt";
// To move a file or folder to a new location:
System.IO.File.Move(sourceFile, destinationFile);
// To move an entire directory. To programmatically modify or combine
// path strings, use the System.IO.Path class.
System.IO.Directory.Move(@"C:\Users\Public\public\test\", @"C:\Users\Public\private");
}
}
using System.IO;
...
string src = "C:\\efe.txt";
string dest = "D:\\efe.txt";
File.Move(src, dest);
string str = "C:\\efe.txt";
string dir = "D:\\";
File.Move(str, Path.Combine(dir, Path.GetFileName(str)));