|
Answer» I have a DIRECTORY with about 30 sub-directories. I want a script that moves files to a ..\XXXX folder if they are OLDER than the most recent 4 files in that folder.
I've figured out how to get the oldest file based on
Code: [Select]CD %FOLDER% set n=4 set i=0 :loop dir /ON /B > ..\dirlist.txt set /P lastfile=< ..\dirlist.txt MOVE %lastfile% ..\temp if %i%==3 set i=4 if %i%==2 set i=3 if %i%==1 set i=2 if %i%==0 set i=1 if %i%==%n% goto end goto loop :end cd .. exit /b 0
I'm trying to cycle through each FOLDER in a Directory. Any ideas?you can cycle threw each folder in a directory with dir /s I'm an idiot, all that does is move the oldest 4 files, not leave the newest 4.set /p a=- ::number of files to skip for /f "tokens=1*" %%a in ('dir /od /b /s') do ( >ECHO %%a>>r) ::echo files by date in to file r
for /f "skip=%a% tokens=1*" %%a in ('type r') do ( echo %%a) [/b] ::replace echo %%a with move %%a %dir%
TRY something like this , prompts for how many files to skip.
|