<分区>
嗯,我不知道怎么打字,所以请耐心等待。
这超出了我的范围,我仍然是 C# 的新手。我基本上需要在运行程序的当前用户的漫游应用程序数据中创建一个文件夹。我还需要访问应用程序数据部分中的另一个文件夹,然后用我创建的应用程序数据文件夹中的文件副本替换文件。
<分区>
嗯,我不知道怎么打字,所以请耐心等待。
这超出了我的范围,我仍然是 C# 的新手。我基本上需要在运行程序的当前用户的漫游应用程序数据中创建一个文件夹。我还需要访问应用程序数据部分中的另一个文件夹,然后用我创建的应用程序数据文件夹中的文件副本替换文件。
最佳答案
前两遍很简单
// The folder for the roaming current user
string folder = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
// Combine the base folder with your specific folder....
string specificFolder = Path.Combine(folder, "YourSpecificFolder");
// CreateDirectory will check if every folder in path exists and, if not, create them.
// If all folders exist then CreateDirectory will do nothing.
Directory.CreateDirectory(specificFolder);
在上次传递中不清楚您要复制的文件在哪里。
但是,假设您有一个名为
string file = @"C:\program files\myapp\file.txt";
File.Copy(file, Path.Combine(specificFolder, Path.GetFileName(file));
MSDN 链接:
关于c# - 如何使用 C# 创建 appdata 文件夹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16500080/