Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 260
  • Last Modified:

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.
0
tenover
Asked:
tenover
  • 8
  • 5
1 Solution
 
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
 
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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
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

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 8
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now