windows - Find folder named with lowest number in a directory , conditional statement on the command line -
i'm new conditional statements command lein, i'd write batch file server running windows server 2003 similar task this, statement find lowest numbered folder (including subdirectories) , copy external drive attached server.
suppose if have folders names 9, 10, 11,... 1023. guess command copy folder (once determined , found) like:
xcopy source:\dir\subdir\9 destination:\dir\subdir\9 /s /e /t
basically, there's large number of files added drive daily , has moved archive on external monthly. how go writing if statement finding folder named of lowest number?
i don't understand lowest numbered folder has added files, i'll assume know doing.
you imply want copy added files, don't want xcopy /t
option. i've added /i
option xcopy assumes destination folder.
the logic identifying lowest folder simple:
1) set low highest possible number in batch (i used hex notation)
2) list directories, using findstr restrict list integer names
3) process list /f. each folder, test if lower current low value. if so, assign folder low.
@echo off setlocal enabledelayedexpansion :: establish source , destination folders set "src=c:\dir\subdir" set "dest=d:\dir\subdir" :: identify lowest folder set /a low=0x7fffffff /f %%a in ('dir /b /ad "%src%"^|findstr /x [0-9]*') if %%a lss !low! set "low=%%a" :: copy lowest folder xcopy "%src%\%low%" "%dest%\%low%" /s /e /i
Comments
Post a Comment