I need an Auto-Delete script...FAST.

I know nothing about scripting, and I need an Auto-Delete script that will go through 5 or 6 directories on a single Windows 2000 server and delete any files older than <x> days.  I'd like it to automatically run once a week.  Possible?  How?  Thanks.
tenoverAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

DVation191Commented:
tenover,
Get xxcopy:
http://www.xxcopy.com/

Use a command like this to move all the old files to a directory you can delete when finished scanning:
xxcopy <SOURCE> <DESTINATION> /Y /RC /DA#<n> /H /E

/RC - Removes files in src after a successful copy (equivalent to move)
/Y - Overwrites existing files without prompting
/DA#<n> - Copies files that were changed on or after <n> days ago.
/H  Copies hidden and/or system files also.
/E  Copies directories and subdirectories, including empty ones.

See here for all parameters: http://www.xxcopy.com/xxcopy01.htm

Then you can use the delete command to delete the files you just moved:
del <DESTINATION>\*.* /s /q


To put this in use in a batch file, put this into notepad and save as "autodelete.bat"
Then set up a scheduled task in the control panel to run the .bat file as often as you'd like

@ECHO OFF
xxcopy <SOURCE> <DESTINATION> /Y /RC /DA#<n>
del <DESTINATION>\*.* /s /q
EXIT

Be SURE to test this first! Although I believe this to be correct it might delete files it shouldn't if you don't test it first. TEST FIRST!
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
tenoverAuthor Commented:
Thanks.  I want to run this on a server weekly and just delete the old files from these 5 directories automatically, I don't want to have to manually move files first....
0
DVation191Commented:
First of all, it's not a manual operation, as the script does it for you. Secondly, its just a temporary holding place, as the built-in delete command in windows does not support deleting by date. XXCopy actually MOVES the files to the temporary holding place (hence the RC parameter), which subsequently gets deleted with the DEL command.
0
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

tenoverAuthor Commented:
Aahh....Ok, I'll try it out and let you know...Thank you.
0
tenoverAuthor Commented:
AWESOME.  That's exactly what I needed.  One thing though, when I ran the .bat file on a couple test folders, I was prompted to copy and to delete all the folders.  As this will be an automated task, do you know off the top of your head if there's a way around the prompting?  Thanks.
0
tenoverAuthor Commented:
Nevermind, I found it.  The switch is /YY, instead of /Y.  Thank you very much.
0
DVation191Commented:
Sure thing! Glad you found it.
0
tenoverAuthor Commented:
Last question.....
Can I have one .bat file copy multiple directories over to the same "Destination" folder?  If so, what is the syntax to seprate the source directories?  Thanks.
0
DVation191Commented:
It's as simple as making the bat file look like this instead:

@ECHO OFF
xxcopy <SOURCE1> <DESTINATION> /Y /RC /DA#<n>
xxcopy <SOURCE2> <DESTINATION> /Y /RC /DA#<n>
xxcopy <SOURCE3> <DESTINATION> /Y /RC /DA#<n>
xxcopy <SOURCE4> <DESTINATION> /Y /RC /DA#<n>
del <DESTINATION>\*.* /s /q
EXIT
0
tenoverAuthor Commented:
Yeah, that's what I ended up doing, thank a lot.
0
tenoverAuthor Commented:
Does this need to work in a certain directory, or run as a certain user?  It works great when I run it on my test workstation, but when I run the edited file on my 2000 server, it doesn't do anything....I took out the /YY, so I'm getting prompted to copy and delete, but everything is still there.  Ideas?
0
DVation191Commented:
No, I'm not really sure what is going on...I mean, clearly the script works (we both tested it using current user permissions), so I'd have to conclude that this is a permissions problem, or possibly, an error in the script. Did you copy the script exactly? Pay attention to the trailing "\" on directories, as it can sometimes make a difference. Otherwise, make sure the scheduled task is running under a user account with the proper permissions.
0
tenoverAuthor Commented:
Damn....It was the back slashes at the end of the directories.  Thanks.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows 2000

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.