c# - 如何使用 C# 创建 appdata 文件夹

标签 c# appdata

<分区>

嗯,我不知道怎么打字,所以请耐心等待。

这超出了我的范围,我仍然是 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 链接:

Path class
Environment.SpecialFolder enum
File.Copy method

关于c# - 如何使用 C# 创建 appdata 文件夹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16500080/

相关文章:

C# REPL 工具;类似控制台的快速编译工具

c# - 序列化 XAML 的 ConcurrentBag

windows-8 - Windows 8 在哪里保存漫游应用程序数据文件?

c++ - 每个 Windows 版本的默认 APPDATA 目录是什么?

c# - 如何在 C# 中使用 HttpClient 发送文件和表单数据

c# - 如何设置扩展文件属性?

c# - 如何将 lambda 表达式转换为 LINQ?

c# - 删除 AppData : Access denied 中的数据库导致崩溃

windows - 如何创建自定义百分比 (%) 快捷方式,如 %appdata%?

visual-studio - Visual Studio 2017 占用本地 AppData 文件夹中的磁盘空间