【发布时间】:2013-07-29 23:49:01
【问题描述】:
所以,基本上我已经创建了这个程序,它将选定的文件复制到公司在 Roaming AppData 文件夹中的命名文件夹中,这还不错。我的意思是,现在的设置还不错,但我希望对它有更多的控制权。
string fullFileName = item.FileName;
string fileNameWithExt = Path.GetFileName(fullFileName);
string destPath = Path.Combine(Application.UserAppDataPath, fileNameWithExt);
File.Copy(item.FileName, destPath);
在程序开始时,它会检查自定义 AppData 文件夹是否存在。
public void checkADfolder()
{
string folder = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
string specificFolder = Path.Combine(folder, ".program");
if (!Directory.Exists(specificFolder))
Directory.CreateDirectory(specificFolder);
}
我希望文件转到 AppData 文件夹 .program 而不是带有应用程序公司名称的文件夹。
另外,我遇到了这个问题。当用户选择一个文件,然后关闭程序并再次打开程序并碰巧选择了相同的文件时,它会给出错误,因为该文件已经存在。 I need to have it overwrite all other files when the same file is selected.
去死吧,我也会问这个我为什么在这里。 我需要用户选择的文件来替换 AppData 文件夹中的另一个文件并重命名用户选择的文件。
基本上。用户选择文件。文件名为“user.txt”。现在它在 Roaming > .program > user.txt 我需要那个文件来替换一个文件,比如说它叫做“guest.txt”。它位于漫游 > .user > guest.txt 我需要将“user.txt”复制并重命名为“guest.txt”,然后替换.user 文件夹中的“guest.txt”。 我希望这能很好地解释一切。
我想我会将所有内容都放在一个帖子中,而不是制作多个帖子。 我已经搜索过,但似乎找不到任何答案:/
【问题讨论】:
-
你用谷歌搜索过复制文件吗?并重命名文件?
标签: c# replace copy rename overwrite