Sort files in name order in a FOR loop

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
panjabi
Posts: 3
Joined: 07 Apr 2008 12:18

Sort files in name order in a FOR loop

#1 Post by panjabi » 08 Apr 2008 07:52

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

DosItHelp
Expert
Posts: 239
Joined: 18 Feb 2006 19:54

#2 Post by DosItHelp » 08 Apr 2008 08:12

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:

Post Reply