Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hi I am trying to get a batch file to delete files which has dates older than 7 days so far I have
@ECHO OFF
CLS
FOR /R C:\User_share %%FILE IN (*.*) DO (
ECHO starting if
IF(0 == (ISDATE %%~zFILE before TODAY -7))
DEL %%FILE
)
Thanks
but when I run I get
%%FILE was unexpected at this time.

I'd like to know more about ISDATE.
=====================================
If at first you don't succeed, you're about average.M2

I actually downloaded from here
[url]http://home.mnet-online.de/horst.muc/[/url]
and info they give is
IsDate compares two dates, including date tags of files and directories, TODAY. Date format acc. to COUNTRY. Optional difference (plus/minus days).
Example: IsDate C:\arc\foo.txt before today-7The result (TRUE/FALSE) is returned by errorlevel.
Features:
LFN support (Win9x/2000/XP)
Comparison operators: [not] =, equal, before, after
Default or custom date format
Internal calculation of day count since Jan 1, 1901 (up to 2079)

Your FOR statement needs:
%%F
or
%%Xor any other SINGLE letter; NOT %%FILE
=====================================
If at first you don't succeed, you're about average.M2

If ISDATE sets errorlevel like it says, instead of this:
IF(0 == (ISDATE %%~zF before TODAY -7))
You may need something more like:
do (
ISDATE %%~tF before TODAY -7
if not errorlevel 1 del %%F
)Note that ~z is SIZE and ~t is DATE/TIME.
=====================================
If at first you don't succeed, you're about average.M2

Now I get
syntax error, file not found or invalid date formatC:\User_share\Inventoryform
RANSLATED.doc
syntax error, file not found or invalid date formatC:\User_share\yedek.doc
syntax error, file not found or invalid date formatC:\User_share\scans\doc.jpg
syntax error, file not found or invalid date formatC:\User_share\scans\doc.zip

Send me ISDATE and I'll try to figure it out.
=====================================
If at first you don't succeed, you're about average.M2

ok here is the direct link for isdate download
http://home.mnet-online.de/horst.muc/int/isdate24.zip

Take a look at this:
::== i5.bat
@echo off
setlocal enabledelayedexpansionfor /f %%F in ('dir/b') do (
echo %%F
ISDATE %%F before TODAY
echo !errorlevel!
echo ===================
)
:: DONE
If at first you don't succeed, you're about average.M2

Hey everybody
Did you solve the problem? If you did, could you please post the whole code... I've got nearly the same problem and i think your resolution is even better then mine.
Cheers

Yeah LOL on follow-up
=====================================
If at first you don't succeed, you're about average.M2

LOL is "lots of luck" intended as a lament.
The OP [original poster] never did say whether it got solved.
Since this thread is about to expire, you may want to start a new one.
=====================================
If at first you don't succeed, you're about average.M2

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

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