moving duplicated directories back to root directory
I accidentally ended up with a bunc开发者_如何转开发h of my directories getting borked, what should be:
/myroot/mydirectory
ended up as:
/myroot/mydirecotry/mydirectory/mydirectory
Then nesting could be any where from 1 to N times - I need to find the furthest out /mydirectory and copy all of those files back to the root and kill the duped ones. How do I find the one that is furthest out?
string[] dirs;
string actualDir = @"\myroot\";
string subdir = "mydirectory";
do
{
dirs = System.IO.Directory.GetDirectories(actualDir, subdir);
actualDir += subdir + @"\";
}
while (dirs.Length > 0);
string theLongestPath = actualDir; // The path to the furthest dir
This gets all directories in actualDir
that contains subdir
, until it's the last one (no other subdirectories containing subdir
). If you have any questions on how it works, ask in a comment. And yeah, I've tried it, it really works.
精彩评论