I accidentally ended up with a bunch 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With