Computing.Net > Forums > Programming > Deleting files based on Date

Deleting files based on Date

Reply to Message Icon

Original Message
Name: aashna_a
Date: April 9, 2007 at 02:29:05 Pacific
Subject: Deleting files based on Date
OS: 2K
Comment:

I need had rename files with the date and then move them to a particular foder.
I have done the renaming and moving thing successfully but now i also need to delete files in tht particular folder based on dates. Each file is stored with the date on which the file had come for eg
test_20070409.txt

i need to keep latest 14 DAYS of data into the folder irrespective of the number of files.

aashna


Report Offensive Message For Removal


Response Number 1
Name: ravi_kv123
Date: April 9, 2007 at 10:48:39 Pacific
Reply: (edit)

hay...i got the code..but need to b tested..
so i wl gv it to u tomm...
but its a perl script
if ur machine is running linux thn no prob..
other wise u need to download activeperl from perl.com
check it out..
i wl gv the code..
bye
ravi

hai


Report Offensive Follow Up For Removal

Response Number 2
Name: FishMonger
Date: April 9, 2007 at 14:15:24 Pacific
Reply: (edit)

Your last statement throws in a little ambiguity.

Do you want to keep the last 14 days based on the filename or on the file's mtime (timestamp of when the file was last modified)?

If you want to use Perl, you can use the -M file test to find the number of days since a file was modified.

If based on the filename, then you need to convert the datestamp in the name to a timestamp that can be compared to “today's” timestamp. There are several Perl modules that help to make this fairly easy.


Report Offensive Follow Up For Removal

Response Number 3
Name: aashna_a
Date: April 9, 2007 at 21:31:37 Pacific
Reply: (edit)

Thanks for the response....
as i have mentioned the files are stored with the dates....the files may not come evryday and on any particular day more than 1 file may also come so i just need 14days of files with repect to the dates.
and i would not be using perl....would have to do this with a batch file.

aashna


Report Offensive Follow Up For Removal

Response Number 4
Name: FishMonger
Date: April 9, 2007 at 21:54:37 Pacific
Reply: (edit)

Perl can do date calculations with 1 line of code, but Batch scripting doesn't have any builtin method for doing this type date calculation, but it might be possible if want to use 3rd party utilities and/or assembly.

Since you don't want to use Perl, I'll bow out and hopefully M2 or IVO will see this thread and help you with a batch file.


Report Offensive Follow Up For Removal

Response Number 5
Name: aashna_a
Date: April 9, 2007 at 22:00:17 Pacific
Reply: (edit)

Thanks a lot anyways FishMonger....

aashna


Report Offensive Follow Up For Removal


Response Number 6
Name: IVO
Date: April 10, 2007 at 01:59:55 Pacific
Reply: (edit)

I agree with FishMonger that the best way to do the job is to code the script in Perl, but if you prefer a lane to the highway, please let us (M2 and me) know

1) The exact format of your timestamped files' names (i.e. are all "test_YYYYMMDD.txt"?);

2) The format of your system date by reporting *exactly* what is displayed typing Echo %date%.



Report Offensive Follow Up For Removal

Response Number 7
Name: aashna_a
Date: April 10, 2007 at 02:47:07 Pacific
Reply: (edit)

1)the exact format is
test_YYYYMMDD.txt

2)and echo%date% gives Tue 04/10/2007

aashna


Report Offensive Follow Up For Removal

Response Number 8
Name: ravi_kv123
Date: April 10, 2007 at 03:35:48 Pacific
Reply: (edit)

ok....if not in perl thn FishMonger may b right..

hai


Report Offensive Follow Up For Removal

Response Number 9
Name: IVO
Date: April 10, 2007 at 03:57:18 Pacific
Reply: (edit)

Quite ready... be patient I'm adapting a script that worked for a guy in Singapore some years ago. Two\tree hours needed due to my duties.


Report Offensive Follow Up For Removal

Response Number 10
Name: aashna_a
Date: April 10, 2007 at 04:04:07 Pacific
Reply: (edit)

i'll be patient..... :) thanks for the help IVO

aashna


Report Offensive Follow Up For Removal

Response Number 11
Name: IVO
Date: April 10, 2007 at 08:43:25 Pacific
Reply: (edit)

Check your mail inbox as I sent you the script. Sorry for the other guys, but the script is too complex to be posted (as FishMonger can easily understand).


Report Offensive Follow Up For Removal

Response Number 12
Name: Soskip
Date: April 12, 2007 at 07:29:59 Pacific
Reply: (edit)

I may be overstepping as a new guy, but take a look at my posting.

http://www.computing.net/programmin...

This is MS-DOS code for deleting files by older-then-x-day, extension, search path, subdirectories search (on/off) and read-only (on/off).

Best Regards,

~Pete


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: Deleting files based on Date

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 In 5 Days.
Discuss in The Lounge