Click here to Skip to main content
15,909,205 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I'm running this batch that works pretty good so far. The only downside is that it searches the entire hard drive everytime. I want to make it quicker. Is there a way that when it runs that it only checks the directory(s) that have changed since the last time it ran. I guess this means that the first time it runs it will check everything, unless it checks for directory(s) that changed today. Just throwing thoughts out there...any help is appreciated. Thanks

@echo off 
setlocal 
for /f "delims=" %%b in ("%time%") do set "tm=%%b" 
set "tm=%tm:~0,5%" 
set "tm=%tm: =0%" 


for /f "tokens=2" %%b in ("%date%") do set "d8=%%b" 


set filespec=\*.zip \*.txt \*.jpg 
for /f "delims=" %%a in (' 
dir %filespec% /a:-d /o:n /b /s') do ( 
if "%%~ta"=="%d8% %tm%" ( 
del "%%a"
) 
)
Posted

1 solution

Unfortunately batch files have no memory.

For your use case it is better you did this in a higher level language which you can store information for your directories.
 
Share this answer
 
Comments
Member 7766180 28-Sep-11 1:50am    
Ok. Thank you. Hey I was just wondering. You see in the code above I'm deleting just zip txt and jpg is there a way to add that to this? Meaning just delete zip txt or jpg instead of all? Thank you.

@echo off
cd "C:\Users\DS\Downloads"
setlocal
call :DateToMinutes %date:~-4% %date:~-10,2% %date:~-7,2% %time:~0,2% %time:~3,2% NowMins
for /f "delims=" %%a in ('dir * /a-d /b') do call :CheckMins "%%a" "%%~ta"
goto :EOF
:CheckMins
set File=%1
:set filespec=\*.zip \*.txt \*.jpg
set TimeStamp=%2
call :DateToMinutes %timestamp:~7,4% %timestamp:~1,2% %timestamp:~4,2% %timestamp:~12,2% %timestamp:~15,2%%timestamp:~18,1% FileMins
set /a MinsOld=%NowMins%-%FileMins%
if %MinsOld% leq 1 del %file%
goto :EOF
:DateToMinutes
setlocal
set yy=%1&set mm=%2&set dd=%3&set hh=%4&set nn=%5
if 1%yy% LSS 200 if 1%yy% LSS 170 (set yy=20%yy%) else (set yy=19%yy%)
set /a dd=100%dd%%%100,mm=100%mm%%%100
set /a z=14-mm,z/=12,y=yy+4800-z,m=mm+12*z-3,j=153*m+2
set /a j=j/5+dd+y*365+y/4-y/100+y/400-2472633
if 1%hh% LSS 20 set hh=0%hh%
if /i {%nn:~2,1%} EQU {p} if "%hh%" NEQ "12" set hh=1%hh%&set/a hh-=88
if /i {%nn:~2,1%} EQU {a} if "%hh%" EQU "12" set hh=00
if /i {%nn:~2,1%} GEQ {a} set nn=%nn:~0,2%
set /a hh=100%hh%%%100,nn=100%nn%%%100,j=j*1440+hh*60+nn
endlocal&set %6=%j%&goto :EOF
Mehdi Gholam 28-Sep-11 1:57am    
for %%1 in (*.jpg, *.txt, *.zip) do something %%1
Member 7766180 28-Sep-11 2:26am    
Thank you, but where in the above batch is it placed? What exactly would fit in? Need help :) Thank you.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900