cctaco2
asked on
Need a way to delete files from a directory, I only want to keep the newest 40 files
I have a program that downloads images every 6 minutes, and the directory grows to be huge and stalls out the computer. but I only want to keep the newest images, I only want to keep 30 of the newest images.
I want a simple .bat script that I will call with a cron job, that would check the directory c:/satelit and delete the older files they are time stampe
I want a simple .bat script that I will call with a cron job, that would check the directory c:/satelit and delete the older files they are time stampe
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
cd/d C:\processed_satelite
for /f "skip=100 delims=" %i in ('dir /b /od') do del "%i"
I placed the script into notepad and saved it as a process.bat and it didn't see to work properly
did I miss something, I'm skipping I think 100 of the newestfiles?
for /f "skip=100 delims=" %i in ('dir /b /od') do del "%i"
I placed the script into notepad and saved it as a process.bat and it didn't see to work properly
did I miss something, I'm skipping I think 100 of the newestfiles?
ASKER
i typed in the commands and got a error
in not expected at this time
in not expected at this time
I tried it on XP and it worked. What OS are you using?
ASKER
Amazaing tech,
Set NumOfFilesToKeep=10
Set Directory=C:\processed_sat elite
FOR /f "Skip=%NumofFilesToKeep% tokens=*" %%a in ('dir /a-d /o-d /b "%Directory%"') do ECHO DEL /q "%Directory%\%%a"
It's not removing the files from the directory, I see it create a ms-dos box and the commands just fly by and then it closes.
This may have some bearing on it the file name is
2008.09.21.1415.gensat.png
thanks
Set NumOfFilesToKeep=10
Set Directory=C:\processed_sat
FOR /f "Skip=%NumofFilesToKeep% tokens=*" %%a in ('dir /a-d /o-d /b "%Directory%"') do ECHO DEL /q "%Directory%\%%a"
It's not removing the files from the directory, I see it create a ms-dos box and the commands just fly by and then it closes.
This may have some bearing on it the file name is
2008.09.21.1415.gensat.png
thanks
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
cd/d C:\your_directory
for /f "skip=30 delims=" %i in ('dir /b /od') do del "%i"
Hope it helps.
Vlad