List Files and Directoy reverse

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Daaka
Posts: 1
Joined: 30 Jan 2011 02:11

List Files and Directoy reverse

#1 Post by Daaka » 30 Jan 2011 02:25

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!

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: List Files and Directoy reverse

#2 Post by aGerman » 30 Jan 2011 06:57

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

Post Reply