views:

114

answers:

1

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.
            }
        }
    }
+5  A: 

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.

Isak Savo
d'oh. Wow, i had no idea there was a difference or even that directory.move exists
acidzombie24