Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hi there,
Thanks for taking the time to read this! I'm trying to write a batch file using MS/DOS on a Windows XP Professional system. I need to delete files from a directory that don't have the archive flag set, and are greater than 60 days old. I believe this would have to be a multiple step process using XCOPY and DEL, but just haven't been able to get it right. Any suggestions?
Cheers,
TanyaNever be afraid to try something new.
Remember that a lone amateur built the Ark. A large group of professionals built the Titanic.

You'd have to edit a few items, but a batch file that does something of what you ask could be found , " Here "
Good luck Huh..
MSI 845e mb 1 gb ram and a p4 2.4n running xp ,win 2000 advanced server and win 98 SE alot to learn and I know so little !!!!

Wish I would'be copied and pasted the text Can't seem to get back to the same page, It was a more involved batch file, and can't get back to it right now,,
After also doing a search on this site, there were some simple batch scripts. that you may be able to modify to suit your purposes...
tried a Google search, and came up with that site first, Hope it works for you the first time and while there ( if it shows up ) be sure and copy and paste the text from it to be able to save it,,, Otherwise you may not be able to see it again,,, Hopefully someone else may be of more Help..
MSI 845e mb 1 gb ram and a p4 2.4n running xp ,win 2000 advanced server and win 98 SE alot to learn and I know so little !!!!

@echo off
set destdir=c:\temp\temp\temp\
for /F "tokens=2,4 delims=/ " %%f in ('date /t') do (
set mm=%%f
set yyyy=%%g
)set yyyy=%yyyy%
if %mm%==02 goto LASTYEAR
set /A mm=1%mm% - 2 - 100
if /I %mm% LSS 10 set mm=0%mm%goto MOVEFILES
:LASTYEAR
set mm=12
set /A yyyy=%yyyy% - 1:MOVEFILES
for %%i in (*.*) do (
set FileName=%%i
call :PROCESSFILE %%~ti
)set destdir=
goto EXIT
:PROCESSFILE
REM ** The time will be dropped
set temp=%1
set fyyyy=20%temp:~6%
set fmm=%temp:~0,2%if /I %fyyyy% GTR 2069 set fyyyy=19%temp:~6%
if /I %yyyy%/%mm% GEQ %fyyyy%/%fmm% (
if exist "%destdir%%FileName%" del "%destdir%%FileName%" > NUL
move "%FileName%" "%destdir%%FileName%"
)set temp=
set fyyyy=
set fmm=:EXIT
set FileName=
set yy=
set mm=You'll want to change the destdir to the directory where you want to move the files.
Note, you can get rid of the line:set yyyy=%yyyy%
Amazed and amused as always
Comment from pwheatstraw
Date: 01/13/2004 01:31PM PST
Author Comment
It seems to be moving everything not modified this month into the destdir, instead of leaving two months worth in the old dir.
Comment from oBdA
Date: 01/13/2004 01:32PM PST
Comment
How about robocopy.exe from the Resource Kit? It's in the NT4/W2k/W2k3 Resource Kit. The former two cost money, the last one can be downloaded for free (and the executable copied to wherever you need it), it just needs to be installed on an XP workstation (or a W2k3 Server installation, obviously); seems to run OK on W2k, probably on NT4 as well. Use an additional /L in the command line to just list the files that would be moved.robocopy.exe SourceDir TargetDir /minage:60 /mov /r:5
W2k3 Resource Kit Tools
http://www.microsoft.com/downloads/details.aspx?familyid=9d467a69-57ff-4ae7-96ee-b18c4790cffd&displaylang=enHave a look at robocopy.doc as well.
Comment from SteveGTR
Date: 01/13/2004 01:41PM PST
Comment
Sorry about that :) Try this:@echo off
set destdir=c:\temp\temp\temp\
for /F "tokens=2-4 delims=/ " %%f in ('date /t') do (
set mm=%%f
set dd=%%g
set yyyy=%%h
)set yyyy=%yyyy%
set /A mm=1%mm% - 2 - 100
if /I %mm% GTR 0 goto MOVEFILES
set /A mm=12 + %mm%
set /A yyyy=%yyyy% - 1:MOVEFILES
if /I %mm% LSS 10 set mm=0%mm%
for %%i in (*.*) do (
set FileName=%%i
call :PROCESSFILE %%~ti
)set destdir=
goto EXIT
:PROCESSFILE
REM ** The time will be dropped
set temp=%1
set fyyyy=20%temp:~6%
set fmm=%temp:~0,2%
set fdd=%temp:~3,2%if /I %fyyyy% GTR 2069 set fyyyy=19%temp:~6%
if /I %yyyy%/%mm%/%dd% GEQ %fyyyy%/%fmm%/%fdd% (
if exist "%destdir%%FileName%" del "%destdir%%FileName%" > NUL
move "%FileName%" "%destdir%%FileName%"
)set temp=
set fyyyy=
set fmm=
set fdd=:EXIT
set FileName=
set yy=
set mm=
set dd=
Accepted Answer from pbarrette
Date: 01/16/2004 09:07AM PST
Grade: A
Accepted Answer
Hey Steve,Whatever happened to the old standby...
It's pretty huge, but it gets the job done error free (usually).
:: ----------MOVEOLD.BAT-------------
@ECHO OFF
SET OLDERTHAN=%1
SET DESTINATION=%2
IF NOT DEFINED OLDERTHAN (GOTO SYNTAX)for /f "tokens=2" %%i in ('date /t') do set thedate=%%i
set mm=%thedate:~0,2%
set dd=%thedate:~3,2%
set yyyy=%thedate:~6,4%set /A dd=%dd% - %OLDERTHAN%
set /A mm=%mm% + 0:LoopDate
if /I %dd% GTR 0 goto DONE
set /A mm=%mm% - 1
if /I %mm% GTR 0 goto ADJUSTDAY
set /A mm=12
set /A yyyy=%yyyy% - 1:ADJUSTDAY
if %mm%==1 goto SET31
if %mm%==2 goto LEAPCHK
if %mm%==3 goto SET31
if %mm%==4 goto SET30
if %mm%==5 goto SET31
if %mm%==6 goto SET30
if %mm%==7 goto SET31
if %mm%==8 goto SET31
if %mm%==9 goto SET30
if %mm%==10 goto SET31
if %mm%==11 goto SET30
if %mm%==12 goto SET31goto ERROR
:SET31
set /A dd=31 + %dd%
goto LoopDate:SET30
set /A dd=30 + %dd%
goto LoopDate:LEAPCHK
set /A tt=%yyyy% %% 4
if not %tt%==0 goto SET28
set /A tt=%yyyy% %% 100
if not %tt%==0 goto SET29
set /A tt=%yyyy% %% 400
if %tt%==0 goto SET29:SET28
set /A dd=28 + %dd%
goto LoopDate:SET29
set /A dd=29 + %dd%
goto LoopDate:DONE
if /i %dd% LSS 10 set dd=0%dd%
if /I %mm% LSS 10 set mm=0%mm%
for %%i in (*.*) do (
set FileName=%%i
call :PROCESSFILE %%~ti
)set mm=
set yyyy=
set dd=
set thedate=
goto EXIT:SYNTAX
ECHO.
ECHO USAGE:
ECHO MOVEOLD X Destinatuib
ECHO Where X is the number of days previous to Today.
ECHO And Destination is the path to move the files to.
ECHO.
ECHO EX: "MOVEOLD 5" Deletes files older than 5 days.
GOTO EXIT:PROCESSFILE
set temp=%1
set fyyyy=20%temp:~6%
set fmm=%temp:~0,2%
set fdd=%temp:~3,2%
if /I %fyyyy% GTR 2069 set fyyyy=19%temp:~6%:: +*************************************+
:: | This is where the files are deleted |
:: | Remove the ECHO command to |
:: | move. ECHO is used for test. |
:: +*************************************+
if /I %yyyy%%mm%%dd% GEQ %fyyyy%%fmm%%fdd% (
ECHO MOVE %FileName% %DESTINATION%
)set temp=
set fyyyy=
set fmm=
set fdd=:EXIT
:: ----------MOVEOLD.BAT-------------pb
Comment from pwheatstraw
Date: 01/19/2004 12:45PM PST
Author Comment
Thanks to both pbarrette and SteveGTR for your help
I wasn't able to get Steve's script to work consistently, but pb's script did the trick
Well was able to get back there , and this time copied and pasted the text from there, You'll have to modify this a little , but should give you an Idea,,, of how to accomplish the task,,,
MSI 845e mb 1 gb ram and a p4 2.4n running xp ,win 2000 advanced server and win 98 SE alot to learn and I know so little !!!!

Thanks very much for the suggestions! Can't wait to try them out... I'll post back with the results for anyone else who is interested.
Cheers,
TanyaNever be afraid to try something new.
Remember that a lone amateur built the Ark. A large group of professionals built the Titanic.

thank you,, And can't wait ,to see your results...
MSI 845e mb 1 gb ram and a p4 2.4n running xp ,win 2000 advanced server and win 98 SE alot to learn and I know so little !!!!

I was able to get the batch file to work fine, but took some more time investigating the robocopy.exe option as well. It turned out to be the better (and quicker) option for me with what I was trying to accomplish. It also allowed me to greatly clean up my existing batch file
Thank you very much for your suggestions! You were a great help!
Cheers,
TanyaNever be afraid to try something new.
Remember that a lone amateur built the Ark. A large group of professionals built the Titanic.

Excellent ,,, Glad you were able to find a solution , Hadn't even thought of trying the Robocopy,, Again ,,,Thanks..!!
MSI 845e mb 1 gb ram and a p4 2.4n running xp ,win 2000 advanced server and win 98 SE alot to learn and I know so little !!!!

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |