Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

moving duplicated directories back to root directory

Tags:

c#

.net

c#-4.0

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?

like image 317
Slee Avatar asked Dec 11 '25 22:12

Slee


1 Answers

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.

like image 195
TomsonTom Avatar answered Dec 14 '25 12:12

TomsonTom