Page 1 of 1

Sort files in name order in a FOR loop

Posted: 08 Apr 2008 07:52
by panjabi
I would like to order the files read in a directory (alphabetically, as in a DIR /o), in a FOR loop.

using the following commands at present.

Any help appreciated. :?

Code: Select all

set echo off
SETLOCAL ENABLEDELAYEDEXPANSION
rem "clear var"
set D=
set T=
set S=
set E=
rem "set vars"
set /p D=[Enter Directory:]
set /p T=[Enter TV Show Name:]
set /p S=[TV Season:]
set /p E=[TV Episode Start:]
set OUTPUT=D:\My Downloads\ipodTvShow\
rem set OUTPUT=F:\ipodTvShow\BAT_Scripts\
set OUTPUT=%OUTPUT%%T%_%S%.bat
rem set D=%1
rem set T=%2
rem set S=%3
rem set /a E=%4
rem "Test Vars"
echo  in F is %D%
echo  in T is %T%
echo  in S is %S%
echo  in E is %E%
echo  in OUTPUT is %OUTPUT%
rem set D=F:\ipodTvShow\BAT_Scripts\test_dir\*.mp4
del %OUTPUT%
for %%F in (%D%) do (
   set /a E=!E!+1
   echo."D:\My Downloads\ipodTvShow\AtomicParsley.exe" "%%F" --stik "TV Show" --TVShowName "%T% Season %S%" --TVSeason %S% --TVEpisodeNum !E! --artist "%T% Season %S%" --writeBack>>%OUTPUT%
)
Pause

Posted: 08 Apr 2008 08:12
by DosItHelp
panjabi,

You might want to use FOR with /f option like this:

Code: Select all

for /f "tokens=*" %%F in ('dir /on "%D%"') do (
    ...
)

DOS IT HELP? :wink: