문제

Its extremely weird since the program is iterating the file! outfolder and infolder are both in H:/ my external HD using windows 7. The idea is to move all folders that only contain files with the extention db and svn-base. When i try to move the folder i get an exception. VS2010 tells me it cant find the folder specified in dir. This code is iterating through dir so how can it not find it! this is weird.

        string []theExt = new string[] { "db", "svn-base" };
        foreach (var dir in Directory.GetDirectories(infolder))
        {
            bool hit = false;
            if (Directory.GetDirectories(dir).Count() > 0)
                continue;
            foreach (var f in Directory.GetFiles(dir))
            {
                var ext = Path.GetExtension(f).Substring(1);
                if(theExt.Contains(ext) == false)
                {
                    hit = true;
                    break;
                }
            }
            if (!hit)
            {
                var dst = outfolder + "\\" + Path.GetFileName(dir);
                File.Move(dir, outfolder); //FileNotFoundException: Could not find file dir.
            }
        }
    }
도움이 되었습니까?

해결책

I believe you are trying to move a whole directory using File.Move which expects a filename.

Try using Directory.Move instead since that allow you to move entire folders around.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top