Computing.Net > Forums > Programming > Need batch file to delete old files

Need batch file to delete old files

Reply to Message Icon

Original Message
Name: dazra
Date: March 15, 2006 at 13:43:24 Pacific
Subject: Need batch file to delete old files
OS: XP pro
CPU/Ram: intel 512
Model/Manufacturer: compaq
Comment:

I need to create a batch file that will compare files and folders on a server to their counter parts on a workstation and delete anything older than a month. For example i have a workstation with a user name joeshmo and his data gets backed up every night to our server with his backup folder being called joeshmo. So this batch file has to be able to check whats in the server joeshmo folder, compare it with the files on his workstation and delete anything older than 30 days. I currently have a batch file that does the backup auto and excludes certain files but i have no idea how to do this. Any help is greatly appreciated.


Report Offensive Message For Removal


Response Number 1
Name: FishMonger
Date: March 15, 2006 at 20:56:26 Pacific
Reply: (edit)

If you're backing up the files each night and only want to delete the files that are 30+ days old, why does the script need to compare the workstation files to the server backup files?


Report Offensive Follow Up For Removal

Response Number 2
Name: dazra
Date: March 16, 2006 at 06:07:59 Pacific
Reply: (edit)

What I am aiming to do is compare the server backup to the workstation backup. The reason we are doing this is because this: Lets say workstation user has a folder with 10 files in it. The backup runs at night and backs those up to the server. The next day user A no longer needs those files and deletes them. At night the backup is going to run, and it won't delete those files off the server. So those files which are no longer needed on the server will remain there. So thats why I'm trying to make a batch file that will check that and delete after 30 days. The 30 days is more or less a just in case they did need it, it will be there for 1 month.


Report Offensive Follow Up For Removal

Response Number 3
Name: FishMonger
Date: March 16, 2006 at 10:50:10 Pacific
Reply: (edit)

So, you're not doing an actual (incremental, differential, or full) backup, but just simply coping the files to the server.

There is no need to compare the files. All you need to do is check the modification timestamp on the server copy and delete it if it hasn't been modified in 30 days. Any file that has a timestamp less than 30 days, tells you that the it's been backed up sometime within that period. Depending on your copy process, it would probably be the same date as the modification timestamp.

Doing date calculations in a batch file is not easy. I would highly recommend using some other scripting language. My recommendation would be to use Perl, but VB or any other language would fine and all would be much better than the batch file.

I can help with a Perl solution to go either direction you want, but if you want the batch file, I'll need to leave it up to someone else to help. Hopefully, IVO or M2 will add their 2 cents.


Report Offensive Follow Up For Removal

Response Number 4
Name: dazra
Date: March 16, 2006 at 12:12:42 Pacific
Reply: (edit)

I've seen M2 respond to people and i've found similar requests but not exact. Only problem is its hard to understand whats going on when a person types out the command %~x$ and you doesn't explain what it means.


Report Offensive Follow Up For Removal

Response Number 5
Name: Mechanix2Go
Date: March 17, 2006 at 00:03:47 Pacific
Reply: (edit)

I'm working on it. And this time I'll include a commented version so others can study it.


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

M2


Report Offensive Follow Up For Removal


Response Number 6
Name: dazra
Date: March 17, 2006 at 08:44:57 Pacific
Reply: (edit)

Thanks M2. I've figured out how to do a dir>text.txt but i'm not sure if thats the route im' suppose to go and how to compare two different text files.


Report Offensive Follow Up For Removal

Response Number 7
Name: dazra
Date: March 17, 2006 at 09:20:34 Pacific
Reply: (edit)

I was just thinking, xcopy has the /d[MM:DD:YY] parameter where you can check a files date. Is there any way to reverse that so that instead of copying nothing it deletes the file?


Report Offensive Follow Up For Removal

Response Number 8
Name: dazra
Date: March 17, 2006 at 09:21:55 Pacific
Reply: (edit)

Sorry, i was also reading one of my response... i'm comparing the workstation to the server. The rest of what i typed is accurate.


Report Offensive Follow Up For Removal

Response Number 9
Name: Mechanix2Go
Date: March 18, 2006 at 02:16:12 Pacific
Reply: (edit)

Quite right about xcopy.

And good thinking.

You could xcopy everything newer than blahblah.

The sticking point remains: date math.

I'm working on a BAT to get "julian" date. And it looks promising. BUT, as ever, there are at least a few dozen layout/language variations.



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: Need batch file to delete old files

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