Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/lua/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何用C创建appdata文件夹#_C#_Appdata - Fatal编程技术网

C# 如何用C创建appdata文件夹#

C# 如何用C创建appdata文件夹#,c#,appdata,C#,Appdata,嗯,我不知道怎么打这些,所以请容忍我 这是我无法理解的,我仍然是C#的新手。我基本上需要在运行程序的当前用户的漫游应用程序数据中创建一个文件夹。我还需要访问“应用程序数据”部分中的另一个文件夹,然后用我创建的“应用程序数据”文件夹中的文件副本替换文件。前两步很简单 // The folder for the roaming current user string folder = Environment.GetFolderPath(Environment.SpecialFolder.Appli

嗯,我不知道怎么打这些,所以请容忍我


这是我无法理解的,我仍然是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 folder exists and, if not, create it.
// If folder exists 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链接:




我建议您在使用时不要担心文件的物理位置。这是一种更灵活的方式-您只需使用隔离存储API,.NET framework负责物理文件的位置(例如,在不同的操作系统中,位置可能不同)。

很抱歉出现了双重发布。。。好的,谢谢你,史蒂夫。现在我知道这是可能的,让我更具体一点。我只需要创建一次。因此,我正在制作一个加载屏幕,它将检查所有必需的东西,比如appdata文件夹等等。我需要它来检查,如果该文件夹已创建,它将通过。如果没有,它将创建它。我知道这将是一件自然而然的事情。所以是 啊另外,我要复制和替换的文件都在应用程序文件夹中。此外,我还需要重命名正在复制的文件。名称必须相同。好的,我已经添加了对CreateDirectory的检查。对于“文件复制”部分,同样需要给出一个示例,说明要复制的文件的命名方式、重命名方式及其位置。使用
应用程序文件夹
是什么意思?好的,我能想到的最简单的例子是Minecraft。因此,minecraft.jar位于appdata.minecraft/bin/minecraft.jar中。假设我想用我自己的替换minecraft.jar,但是如果我的名为_minecraft.jar,那就行不通了。我需要更改文件名。因此,它复制appdata/.myfolder/_minecraft.jar并重命名和替换appdata/.minecraft/bin/minecraft.jar。这有意义吗?而且,它给了我这个。。。。使用System.IO添加
到文件的开头