Looking through the site, the file date script http://www.dostips.com/BatchFTime.bat is 95% of what I need.
This script tells you how many days old a file is. What I want to add to it is, if the age of the file is older than 5 days, then pass the filename to a Dos MOVE command to move the file from the current directory to a subdir named OLD.
I tried to add new code myself but the syntax with all the parameters and variables, etc., is just too confusing, and it won't loop more than once before it errors out.
Here's what I tried to add at the top (line marked in BOLD):
@echo off
SETLOCAL ENABLEEXTENSIONS
SETLOCAL ENABLEDELAYEDEXPANSION
cd /d c:\temp\log
call:jdate tnow "%date%"
for %%F in (*.*) do (
call:ftime tfile "%%F"
set /a diff=tnow-tfile
echo.%%~nxF is !diff! days old
call:moveit "%%F" !diff!
)
and then I added a new function section at the bottom:
:moveit -- if file is too old, move it to the OLD directory
echo [in moveit now] %1 %2
if %2 >= 5 then echo File is too old
rem move %%1% c:\temp\log\old
EXIT /b
refer to the original full file I linked above for the full context. I just need it to pass the filename, the age in days value to the moveit function, and in that code if more than my threshold, move the file to the OLD subdir, and then return back to the file loop to continue.
need a variant of
Moderator: DosItHelp
Re: need a variant of
Just to help prevent making your script too complicated…
Robocopy can select files to move, /MOV, based upon their age, /MINAGE:5 will select all files which are older than five days.
Forfiles can select files to run a series of commands on using the date, /D, option.
Type robocopy /? and/or forfiles /? into your Command prompt window for more information on these two commands.
Robocopy can select files to move, /MOV, based upon their age, /MINAGE:5 will select all files which are older than five days.
Forfiles can select files to run a series of commands on using the date, /D, option.
Type robocopy /? and/or forfiles /? into your Command prompt window for more information on these two commands.
-
- Posts: 3
- Joined: 25 May 2017 09:57
Re: need a variant of
thanks for the tip. Where does one obtain a full copy of "robocopy" ? Can you provide a direct link?
-
- Posts: 3
- Joined: 25 May 2017 09:57
Re: need a variant of
Never mind my previous reply. I found Robocopy is a native DOS command. Works great for my purpose! Thanks again for the tip.