【问题标题】:How can I copy my program into a different place on my computer?如何将我的程序复制到计算机上的不同位置?
【发布时间】:2014-10-02 20:12:49
【问题描述】:

我现在如何将我的程序从其源代码复制到不同的文件夹(使用 C# 代码)?

P.S:我的下载文件夹的 C# 源代码是什么?

我不知道该怎么做:/

感谢帮助:-)

【问题讨论】:

标签: c# download copy


【解决方案1】:

复制程序与复制任何其他文件没有什么不同。您可以使用操作系统的工具来查看和移动文件。您可以使用图形界面执行此操作,例如:Mac OSX 上的 Finder,或 Windows 上的 Windows Explorer。或者,如果您更愿意使用命令行工具,请在类 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);

【讨论】:

  • 我希望它由我的程序完成,我不想自己做。我询问了执行此操作的代码。
  • 这甚至没有尝试以编程方式回答问题。
  • 我误解了你的问题。虽然我不精通 C#,但我正在更新我对微软文档的回答,解释如何做到这一点。
猜你喜欢
  • 1970-01-01
  • 2013-02-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多