|
Answer» Okay,
Suppose i have a directory structure
A/B/C/D Inside it i have more directories.
Now i have to take a listing: I do dir /b/s
Now comes the problem: This listing is like A/B/C/D/a.txt A/B/C/D/E/a.txt A/B/C/D/E/F/a.txt A/B/C/D/E/F/G/a.txt
I want the output like a.txt E/a.txt E/F/a.txt E/F/G/a.txt
How can i do it.You would have to parse each directory entry USING the FOR statement and using the backslash as a delimiter. Should be fun when the paths contain various levels of nesting:D I'm not SURE where you're going with this but file names include the drive, path, filename and extension. Partial paths are only practical when using relative path addressing. (. and ..)
Happy Computing. The thing is that:
I have a huge directory structure and i have to prepare a listing of that.
If i do that with the help of simple dir /b/s then the entries scroll down to next line and on copying to a text editor they are not in same line.
With for loop also i don't THINK this can be achieved. Because how do you set the delimitor if you don't know how many backslashes you will get.Using the backslash as the delimiter is the easy part. You could either run a massive directory list and count the largest number of backslashes or just take an educated guess and see what results. You can always account for more or less tokens.
Something like this would account for up to 10 levels of nesting:
Code: [Select] for /f "tokens=1-10 delims=^\" %%a in ('dir * /s /b') do ( echo whatever )
Starting backwards from the last defined variable (%%j in this example), you would have to check each variable for blanks, and echo back the last three (or whatever) variables that are not blank.
Question: Why are you using so many NESTED levels in your structure?
Good luck. I have already explained the problem.
I think its a practical situation in real life. Wouldn't you be having a directory structure with about 10 levels of nesting.
And you want to prepare a list of it. But want only a certain hierachy of it.
|