如何将我的程序从源文件复制到另一个文件夹(使用C#代码)?
P.S:我的下载文件夹的C#源代码是什么?
我不知道怎么做:/
感谢帮助者: - )
答案 0 :(得分:0)
复制程序与复制任何其他文件没有什么不同。您可以使用操作系统的工具来查看和移动文件。您可以使用图形界面执行此操作,例如:Mac OSX上的Finder或Windows上的Windows资源管理器。或者,如果您更愿意使用命令行工具,请在类似Unix的系统上使用cp
,或在Windows上使用copy
。
如果要编辑C#程序中的文件,则必须使用标准库来访问文件系统(文件和文件夹)。 Microsoft提供的文档可能对您有所帮助:
How to: Get Information About Files, Folders, and Drives (C# Programming Guide)
How to: Copy, Delete, and Move Files and Folders (C# Programming Guide)
从上面的链接中提取的最小示例:
string fileName = "test.txt";
string sourcePath = @"C:\Users\Public\TestFolder";
string targetPath = @"C:\Users\Public\TestFolder\SubDir";
// Use Path class to manipulate file and directory paths.
string sourceFile = System.IO.Path.Combine(sourcePath, fileName);
string destFile = System.IO.Path.Combine(targetPath, fileName);
// To copy a file to another location and
// overwrite the destination file if it already exists.
System.IO.File.Copy(sourceFile, destFile, true);