0

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?

alesinho
  • 3
  • 4

3 Answers3

0

try this

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

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

Loïc MICHEL
  • 24,935
  • 9
  • 74
  • 103
  • This could be perfect but just returns the files of the last folder, beacuse when you use "call :filesOF" you ends the fisrt for loop. I like this way to solve my problem, it would be ok to improve this code. – alesinho Aug 13 '14 at 11:41
  • if I put a "exit /b" after second for it works perfect, makes complete loop. Thanks!!! – alesinho Aug 13 '14 at 11:58
0
@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

rostok
  • 2,057
  • 2
  • 18
  • 20