Discussion Locked

Automatic deletion of dated files

0 helpful
6 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.
I am running a Windows 2000 server which recieves a copy of a text file that was created by UNIX/Cobol application. What I want to have the ability to achieve is to delete these text files automatically on a certain day but leaving that weeks worth of text files on the server. So basically I want to automate deleting last weeks text files while leaving this weeks. Can a batch file be written that will check the date of the file and compare against the server calendar to make the deletion decision? If so how?

6 replies

by chris910

what is the structure of the filename?
Are there other files in the folder besides the ones you want to delete?

by tbwolfe

Chris -- you answered the question with a question. There are multiple files created on a daily basis with the file name being about 18 characters, with the last 10 charaters being different - it is the date code. So, can I write a script that tells it to compare the date of the file with today's date and delete if it is greater then 7 days old?

by shawn

I think the best way would be to write a .vbs script that:

-creates a variable for the date in the required format
-inventories the contents of your folder (using the FileSystemObject object)
-compares the last 10 characters of the file names with the date variable and deletes the ones that are older than you want to keep

You could then schedule this script to run once a day with the task scheduler.

Kinda vauge, I know, but I will look at the actual syntax required when I get a free moment (busy at work with a domain migration right now :oS )

Cheers,
Shawn

This discussion is closed to new replies.