dcsimg
How to delete certain files in a Directory
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Anonymous
Posted On:   Thursday, June 2, 2005 12:02 AM

Hi All, I have a directory which consists files in following format, "XYZ.20050530.txt" , "XYZ.20050531.txt" , "XYZ.20050601.txt" , "XYZ.20050602.txt" etc., Format : "XYZ" + date + ".txt" My requirement is to delete all the files in this directory which are not belongs to certain dates. Ex: leaving last 2 days files, i need to delete all the files in that directoy..... can anybody tell me the logic to delete the files with above criteria... Thanks, Prasad    More>>

Hi All,
I have a directory which consists files in following format,

"XYZ.20050530.txt" ,

"XYZ.20050531.txt" ,

"XYZ.20050601.txt" ,

"XYZ.20050602.txt" etc.,




Format : "XYZ" + date + ".txt"


My requirement is to delete all the files in this directory which are not belongs to certain dates.
Ex: leaving last 2 days files, i need to delete all the files in that directoy.....


can anybody tell me the logic to delete the files with above criteria...



Thanks,
Prasad

   <<Less

Re: How to delete certain files in a Directory

Posted By:   Christopher_Koenigsberg  
Posted On:   Thursday, June 2, 2005 11:57 AM

can anybody tell me the logic to delete the files with above criteria


1. Determine the current criteria, if dynamic (strings representing the last 2 days).


2. Read the list of files in the directory.


3. Parse each filename, compare against the criteria strings.


4. Delete if not a match.

About | Sitemap | Contact