Computing.Net > Forums > Programming > Batch file to delete files in a dir

Batch file to delete files in a dir

Reply to Message Icon

Original Message
Name: rojanu
Date: August 2, 2006 at 11:56:59 Pacific
Subject: Batch file to delete files in a dir
OS: Windows XP SP2
CPU/Ram: intel p4 1024 Mb ram
Comment:

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.


Report Offensive Message For Removal


Response Number 1
Name: rojanu
Date: August 2, 2006 at 11:59:19 Pacific
Reply: (edit)

ooops sorry!
ISDATE is another executable batch file on the path used to compare dates



Report Offensive Follow Up For Removal

Response Number 2
Name: Mechanix2Go
Date: August 2, 2006 at 12:40:50 Pacific
Reply: (edit)

I'd like to know more about ISDATE.


=====================================
If at first you don't succeed, you're about average.

M2



Report Offensive Follow Up For Removal

Response Number 3
Name: rojanu
Date: August 2, 2006 at 13:20:12 Pacific
Reply: (edit)

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-7

The 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)


Report Offensive Follow Up For Removal

Response Number 4
Name: Mechanix2Go
Date: August 2, 2006 at 14:39:17 Pacific
Reply: (edit)

Your FOR statement needs:

%%F
or
%%X

or any other SINGLE letter; NOT %%FILE


=====================================
If at first you don't succeed, you're about average.

M2



Report Offensive Follow Up For Removal

Response Number 5
Name: rojanu
Date: August 3, 2006 at 07:27:03 Pacific
Reply: (edit)

ok but now I get
) was unexpected at this time.


Report Offensive Follow Up For Removal


Response Number 6
Name: Mechanix2Go
Date: August 3, 2006 at 08:29:28 Pacific
Reply: (edit)

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



Report Offensive Follow Up For Removal

Response Number 7
Name: rojanu
Date: August 4, 2006 at 09:51:46 Pacific
Reply: (edit)

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


Report Offensive Follow Up For Removal

Response Number 8
Name: Mechanix2Go
Date: August 4, 2006 at 19:43:44 Pacific
Reply: (edit)

Send me ISDATE and I'll try to figure it out.


=====================================
If at first you don't succeed, you're about average.

M2



Report Offensive Follow Up For Removal

Response Number 9
Name: rojanu
Date: August 7, 2006 at 09:51:36 Pacific
Reply: (edit)

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


Report Offensive Follow Up For Removal

Response Number 10
Name: Mechanix2Go
Date: August 7, 2006 at 12:50:29 Pacific
Reply: (edit)

Take a look at this:

::== i5.bat
@echo off
setlocal enabledelayedexpansion

for /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


Report Offensive Follow Up For Removal

Response Number 11
Name: acs-crew
Date: September 22, 2006 at 04:48:08 Pacific
Reply: (edit)

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


Report Offensive Follow Up For Removal

Response Number 12
Name: Mechanix2Go
Date: September 22, 2006 at 05:27:52 Pacific
Reply: (edit)

Yeah LOL on follow-up


=====================================
If at first you don't succeed, you're about average.

M2



Report Offensive Follow Up For Removal

Response Number 13
Name: acs-crew
Date: September 22, 2006 at 05:50:59 Pacific
Reply: (edit)

What do you mean "Yeah LOL on follow-up"?



Report Offensive Follow Up For Removal

Response Number 14
Name: Mechanix2Go
Date: September 22, 2006 at 06:31:13 Pacific
Reply: (edit)

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



Report Offensive Follow Up For Removal






Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: Batch file to delete files in a dir

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software




Have you ever used OpenOffice?

Yes, as my main suite.
Yes, occationally.
Yes, but only once.
No, never.


View Results

Poll Finishes Today.
Discuss in The Lounge