# Delete old files on a network share using batch file



## mattartist (Mar 21, 2006)

Hi guys,

Looking to this forum for some help with writing a batch file.

I would like to delete 5 day old files from a network share using a sched task .bat to make room for additional daily backups. I have gotten by with very basic batch files before but I really don't know where to start writing this in terms of how to select the 'old' files to delete.  The process would also have to include subfolders.

I'd schedule this to run every morning.

The share is, P:\ 

With many thanks in advance,

Matt


----------



## JohnWill (Oct 19, 2002)

I'd use something like AutoIt to write a simple script to do the task.


----------



## cancon (Jul 22, 2005)

I hope u don't take me to be ignorant, but what's a batch file?


----------



## JohnWill (Oct 19, 2002)

What's a batch file?


----------



## cancon (Jul 22, 2005)

ok, thanx!


----------



## mattartist (Mar 21, 2006)

JohnWill said:


> I'd use something like AutoIt to write a simple script to do the task.


Thanks John. Font of knowledge as ever. Looks interesting. Will see how it goes ...


----------



## mattartist (Mar 21, 2006)

My word, AutoIt is a bit overwhelming for a scripting virgin like me!  Seems a bit like group policy where you have to be creative - if not lucky - with what functions are there to use. Judging from the forums, it looks like it could help, but means I have to learn the program and the nuances of scripting - which I haven't the brains for!!

Is there any other way to achieve this 'old backup deletion'?


----------



## JohnWill (Oct 19, 2002)

I'm not sure any of the "other" methods would be simpler than Autoit.  You're looking for a somewhat complex solution here, since you have to check the file dates to determine which to delete, not to mention the multiple folders. It's going to take a bit of work to accomplish this.


----------



## mattartist (Mar 21, 2006)

Just as I feared. Thanks for your thoughts john. Much appreciated. 

I'm off to the AutoIt Help files ...


----------



## Bob Cerelli (Nov 3, 2002)

JohnWill said:


> I'd use something like AutoIt to write a simple script to do the task.


Looks pretty promising. For those that haven't used it yet, but most importantly for mattartist, could an example script be posted? Just to get him on his way.


----------



## Frank4d (Sep 10, 2006)

If you want to stick with a batch file you could write one that...
Uses XCOPY to copy all files newer that a specified date (/D switch) to a temp folder that is not located on the share.
Then RD /S /Q to delete all files and folders from the share
Then XCOPY to copy everything from the temp folder back to the share.

Not elegant, but would work.


----------



## mattartist (Mar 21, 2006)

Thanks for all the responses guys.

Hopefully we've got a resolution that avoids manual scripting. A friend has pointed me in the direction of a program called *Delanda*. Looks like it does exactly what I want - i.e. purge files x hours/days/months old daily.

Will post to its effectiveness once I've lived with it ...


----------

