Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
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.

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?

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.

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.

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.

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

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.

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?

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.

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

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |