You are not logged in.
Related to
http://ss64.com/nt/for_f.html
for /f "tokens=* skip=3" %%F in ('dir %myDir% /o-d /tc /b') do del %myDir%\%%F
skips the first 3 files and processes all the others
I need just the opposite : processing the first 3 and skipping all the others
How could this been done ?
Thanks
Offline
You can count the number of files with find and then subtract three, reverse the sort in the for loop and use the resulting number in the skip field.
Or use delayedexpansion and a counter in the loop, only deleting until the counter is up to 3.
Or this will give you the first three in variables:
@echo off
set "file=%temp%\file.txt"
dir %myDir% /o-d /tc /b >"%file%"
(
set /p delfile1=
set /p delfile2=
set /p delfile3=
)<"%file%"
set delfile
del "%file%"
pause & goto :EOF
Offline
for /f "tokens=1,* delims=[]" %A in ('dir /b ^| find /n /v ""') do @if %A leq 3 @echo %B
Offline
Thank you folks !
Exactly what I needed to proceed
Offline