Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/312.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#_Io_Filesystems - Fatal编程技术网

C# 将文件夹移动到同一命名文件夹

C# 将文件夹移动到同一命名文件夹,c#,io,filesystems,C#,Io,Filesystems,我有一些文件夹,我在程序运行时检查它们。 我删除不必要的文件夹,并将选中的文件夹返回到其他目录 我的问题是,我总是有例外。我真的不知道为什么。 顺便说一句:当前表和新表具有相同的名称 : 翻译,因为它是德语:无法创建数据,因为它已经存在。 我的代码: public void CreateCheckedStructure(){ List checkedDirNew=Program.RemoveTempFolders(GetAllFromDir(Settings.Default.NewFolder)

我有一些文件夹,我在程序运行时检查它们。 我删除不必要的文件夹,并将选中的文件夹返回到其他目录

我的问题是,我总是有例外。我真的不知道为什么。 顺便说一句:当前表和新表具有相同的名称 : 翻译,因为它是德语:无法创建数据,因为它已经存在。 我的代码:

public void CreateCheckedStructure(){
List checkedDirNew=Program.RemoveTempFolders(GetAllFromDir(Settings.Default.NewFolder));
列表checkedDirCurrent=Program.RemoveTempFolders(GetAllFromDir(Settings.Default.CurrentFolder));
foreach(checkedDirNew中的字符串checkedNew){
DirectoryInfo dirInfoNew=新的DirectoryInfo(checkedNew);
foreach(checkedDirCurrent中的字符串checkedCurrent){
DirectoryInfo dirInfoCurrent=新的DirectoryInfo(checkedCurrent);
if(dirInfoNew.Name.Equals(dirInfoCurrent.Name)){
字符串checkedFoldersPath=Settings.Default.CheckedTables+“\\”+dirInfoCurrent.Name;
CreateDirectory(checkedFoldersPath);
目录.CreateDirectory(选中Folderspath+“\\New”);
目录.CreateDirectory(选中Folderspath+“\\Current”);
dirInfoCurrent.MoveTo(选中folderspath+“\\Current”);
dirInfoNew.MoveTo(选中folderspath+“\\New”);
打破
}
}        
}
}

您正在创建
checkedFoldersPath+“\\New”
,然后尝试在上面复制另一个文件夹。发生此错误是因为它已存在。如果试图合并这两个文件夹,则必须将所有子文件和子目录(递归)移动到新文件夹,然后删除原始文件夹


查看以下答案:

我编辑了我的问题:)谢谢您的回复!
public void CreateCheckedStructure() { 

        List<string> checkedDirNew = Program.RemoveTempFolders(GetAllFromDir(Settings.Default.NewFolder));
        List<string> checkedDirCurrent = Program.RemoveTempFolders(GetAllFromDir(Settings.Default.CurrentFolder));

        foreach(string checkedNew in checkedDirNew){

            DirectoryInfo dirInfoNew = new DirectoryInfo(checkedNew);
            foreach (string checkedCurrent in checkedDirCurrent) {
                DirectoryInfo dirInfoCurrent = new DirectoryInfo(checkedCurrent);
                if(dirInfoNew.Name.Equals(dirInfoCurrent.Name)){
                    string checkedFoldersPath = Settings.Default.CheckedTables + "\\" + dirInfoCurrent.Name;
                    Directory.CreateDirectory(checkedFoldersPath);
                    Directory.CreateDirectory(checkedFoldersPath+"\\New");
                    Directory.CreateDirectory(checkedFoldersPath + "\\Current");
                    dirInfoCurrent.MoveTo(checkedFoldersPath + "\\Current");
                    dirInfoNew.MoveTo(checkedFoldersPath + "\\New");
                    break;
                }
            }        
        }

    }