|
|
|
Batch file to delete files in a dir
|
Original Message
|
Name: rojanu
Date: August 2, 2006 at 11:56:59 Pacific
Subject: Batch file to delete files in a dirOS: Windows XP SP2CPU/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 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 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 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 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:
|
|

|