Page 1 of 1

List Files and Directoy reverse

Posted: 30 Jan 2011 02:25
by Daaka
Hello,
I need to get a list of files and directories in a pathname.
The important thing is to have the directory "fathers" at the bottom of the list.
Example. From...

directory
try4.txt
try5.txt
directory\directory2
directory\directory3
directory\try3.txt
directory\directory2\try.txt
directory\directory3\try2.txt

to:
directory\directory3\try2.txt
directory\directory2\try.txt
directory\try3.txt
directory\directory3
directory\directory2
try5.txt
try4.txt
directory

I tried using all the parameters of 'dir' (sort, etc) but there's nothing that gives me this result.


Thanks!

Re: List Files and Directoy reverse

Posted: 30 Jan 2011 06:57
by aGerman
Hmm if I don't get you wrong then you try to display the output of DIR upside down.
This could be a possible way:

Code: Select all

@echo off &setlocal

for /f "tokens=1* delims=:" %%a in ('dir /b /s^|findstr /n .') do (
  set /a n=%%a
  set "line_%%a=%%b"
)

setlocal enabledelayedexpansion
for /l %%i in (%n%,-1,1) do (
  echo(!line_%%i!
)
endlocal

pause


Regards
aGerman