![]()
[<<]Message[>>] [<<]Author[>>] [<<]Subject[>>] [<<]Thread[>>]
Number : 4543 Date : 2003-05-06 Author : daverunda Subject : Re: Deleting folders based on folder date Size(KB) : 4
MY OS is Windows 2000 SP3. The date format is mm-dd-yy but that can be easily changed (and should be) with no negative consequences. The deletion of all directories created more than X (lets assume 5) days ago must be automated, invoked from a batch file that is scheduled to run every night at 2:00 AM. The only directories it needs to check are the directories in the root of the K:\ drive. For example, lets say there are three directories located as follows: k:\05-01-03\ k:\05-05-03\ k:\05-10-03\ I want XXCOPY to simply check the creation date on these three parent folders and then delete any which are older than 5 days. It does not need to check the creation dates of any sub-directories or files inside these parent folders...if the creation date of the parent directory (e.g. k:\05-01-03) is older than 5 days, then delete that folder and everything in it. If the creation date of the parent folder (e.g. k:\05-10-03) is less than 5 days old, then leave it alone. I think I would prefer a batch approach as you suggest because it doesn't seem that XXCOPY is well suited to this task. Any batch file suggestions you may have would be greatly appreciated. The batch files I am using now are as follows: START of C:\WINNT\FULLBU.BAT FILE @ECHO ON net use k: /delete /y net use k: \\joanne\serverbu-joanne rem the following gets date and time into e-vars rem Requires c:\winnt\CURRENT.BAT ECHO.|DATE>c:\winnt\TEMPDTTM.BAT CALL c:\winnt\TEMPDTTM.BAT md "k:\%DATE%" xxcopy "c:\company data" "k:\%DATE%" /y/v/e/s/c/i/h/r/h/ze/nx/on"k:\% DATE%.txt" xxcopy k: /rs/s/h/r/pd0/ed/db#5/fc/y/on"k:\deleted-%DATE%.txt" net use k: /delete END OF FULLBU.BAT file START of C:\WINNT\TEMPDTTM.BAT Current date is Tue 05-06-2003 Enter new date (mm-dd-yy): END of TEMPDTTM.BAT START of C:\WINNT\CURRENT.BAT if '%1'=='date' GOTO IsDate set Time=%3 GOTO End :==== IsDate ==== SET DayOfWeek=%3 SET Date=%4 :==== End ==== END of CURRENT.BAT --- In xxcopy@yahoogroups.com, "garrydeane" wrote: > --- In xxcopy@yahoogroups.com, "daverunda" wrote: > > I have a batch file that uses XXCOPY to create a folder > > named %DATE% on my D: drive and copy the contents of my > > C:\DATA folder into the D:\%DATE% folder. This system > > works great except that after a while I need to purge > > some of these old backup folders. I asked Kan if I can > > use XXCOPY to delete old folders on my D: drive based > > on the folder creation date. His reply is as follows: > > > > > It seems that you are using W2k or XP if you are using the %date% > system variable or did you mean the $date$ macro? If you are using > W2k/XP there are a number of batch methods you could use however > let's stick to what Xxcopy can do. > > Because %date% will produce a date format according to your > particular locale settings, I'll assume you have a directory created > 10 days ago which looks like D:\2003-04-26\. You'll need to adjust > the following to suit whatever date format you are using. > > Xxcopy could create that directory using a command like: > > xxcopy c:\data\ d:\/$yyyy-mm-dd$\ /bu > > To remove a directory which was created 10 days ago, you can use > the /TM switch to offset the date used in the macro to 10 days ago. > > xxcopy d:\/$yyyy-mm-dd$\ /rmdir/rsy/tm-10 > > Of course this will only delete the single directory which matches > the date 10 days ago (not anything older) but on the assumption that > you would be running this in a daily batch, that's OK. If you are > running this only occasionally you might do something like delete all > directories created during the month (approximately) 2 months ago. If > run today, the following would delete all directories created in > March. > > xxcopy d:\/$yyyy-mm$*\ /rmdir/rsy/tm-61 > > Another approach you might consider (if you're game) is to use Xxcopy > to list the directories created AFTER the date of the directories you > want to keep. Then use Xxcopy to remove the directories EXCLUDING > those in the list you have just created. > > xxcopy d:\ /ltree/da#10/fc/foc:\save.lst > xxcopy d:\ /rmdir/rsy/exc:\save.lst > > This is a pretty risky approach however because if something goes > awry, you might lose all your backup data. I'd test VERY thoroughly > before attempting this. > > There's probably a number of other possibilities along these lines > but I'll leave that for you to play with. If you want a batch > approach, let us know which OS and date format you are using. > Depending on these, it may be quite simple to do in batch using the > output from a /LTREE/DB#nn/FC command. > > Garry
This message if part of XXCOPY's message Archive. The archive contains all the messages posted at Yahoo!Groups: XXCOPY.