0
votes

I'm triying to get a list of files of subfolders in a inverse order using this:

for /f "tokens=*" %%f in ('dir /s /b /o-n') do (echo %%f)

I'm getting this result folder1\file2, folder1\file, folder2\file2, folder2\file1, folder3\file2, folder3\file1

And I want to get the reverse order in folders and files, not only files of folders. Something like this folder3\file2, folder3\file1, folder2\file2, folder2\file1\, folder1\file2, folder1\file1

How can I do this?

3

3 Answers

0
votes
@echo off
for /f "tokens=*" %%f in ('dir /s /b /o-n') do (echo %%f >> tempfile.123)
C:\Windows\System32\sort.exe /R tempfile.123
del tempfile.123

This just echoes your files to tempporary file and then revereses it. Sorry for the full path to sort.exe but I have cygwin installed. In case you want proper temporary file name I reccomend this http://unserializableone.blogspot.com/2009/04/create-unique-temp-filename-with-batch.html

0
votes

try this

for /f "tokens=*" %%f in ('dir /s /b /o-n') 
    do (
        SET OUTPUT=%OUTPUT%, %%f
    )
echo %OUTPUT%
0
votes

run a first loop to get first level subdir then run you command on each of them

@echo off
for /f "tokens=*" %%f in ('dir c:\temp\so\ /b /o-n /AD') do (call :filesOf %%f)

:next
echo next
pause

:filesOf 
echo "files for  ******** %1 *********"
if ("%1"=="") goto next else(
 for /f "tokens=*" %%i in ('dir c:\temp\so\%1 /s /b /o-n ') do echo "***%%i***"
 )

it will be difficult to handle multi level subdirs tough