Link to home
Start Free TrialLog in
Avatar of Sulcata
Sulcata

asked on

Delete all files in tree over 7 days old

I need a script or line that can be added to this one to delete all folders and files created by the following script that are older than 7 days old. Will be run from XP,2000 and 98se.

REM This backs up the H:\ drive at log off
REM Place in user_config/windows_settings/scripts/logoff
REM This section was found at https://www.experts-exchange.com/questions/20268763/Create-subdirectory-name-based-on-date-and-time.html

REM ----------------- this creates a date string

for /f "tokens=2-4 delims=/ " %%a in ('Date /T') do set DateVar1=d%%c%%a%%b
for /f "tokens=1-3 delims=: " %%a in ('TIME /T') do set TimeVar1=t%%a%%b%%c%
SET DateVar=%DateVar1%\%TimeVar1%

MD c:\DailyLocal\%VarVar%

REM ----------------- this determines if the directory exists before creating one
IF NOT EXIST C:\DailyLocal\%DateVar%\NUL MD C:\DailyLocal\%DateVar%

REM copies file from and to directory
xcopy /E /Y /Q /k /I H\:*.* c:\DailyLocal\%DateVar%
Avatar of dbrunton
dbrunton
Flag of New Zealand image

This link talks about what you want

https://www.experts-exchange.com/questions/20164223/Deleting-Files-in-DOS-based-on-Date.html

There are links to utils for date deleting and also a batch file that does that as well
ASKER CERTIFIED SOLUTION
Avatar of rin1010
rin1010

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Sulcata
Sulcata

ASKER

rin1010, you are right about the variables not working under win98. We are 3 wks away from upgrading those systems so I am not going to worry about them to much.
Thank you for the programs they work great!