File.Move, why do i get a FileNotFoundException? The file exist...

Posted by acidzombie24 on Stack Overflow See other posts from Stack Overflow or by acidzombie24
Published on 2010-03-27T07:14:01Z Indexed on 2010/03/27 7:23 UTC
Read the original article Hit count: 239

Filed under:
|

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.
            }
        }
    }

© Stack Overflow or respective owner

Related posts about .NET

Related posts about filenotfoundexception