2

I have a shared disk that I would like to clean up once per week using a scheduled task of some sort. I would like to use a batch script so that the system admins can easily modify it or reuse it on other directories when needed.

The directory has files with multiple file extensions but the ones that need to be deleted end in .bkf and must be over 2 weeks old.

Does anyone have a batch script solution for this windows server (not sure which version)?

Joe Phillips
  • 49,743
  • 32
  • 103
  • 159
  • http://stackoverflow.com/questions/324267/batch-file-to-delete-files-older-than-a-specified-date http://stackoverflow.com/questions/51054/batch-file-to-delete-files-older-than-n-days – BlueRaja - Danny Pflughoeft May 11 '10 at 18:33

4 Answers4

1

If you have PowerShell (or can install it), check out this link: http://thepowershellguy.com/blogs/posh/archive/2007/12/13/hey-powershell-guy-how-can-i-delete-files-that-are-a-specified-number-of-hours-old.aspx

Austin Salonen
  • 49,173
  • 15
  • 109
  • 139
  • I can't unfortunately. Windows batch is all. – Joe Phillips Jan 09 '09 at 21:18
  • 1
    I think it's installed by default in Windows Server 2008. You might want to work with your sysadmins to see if it can be installed. MS is pushing it to be the server maintenance tool (a lot 2008 commands are built on PowerShell). – Austin Salonen Jan 09 '09 at 22:23
1

Take a look at this page - scheduling tasks from command line

It shows you hot to create scheduled tasks from the command line. You might be able to use this in combination with other dos commands to get your result.

The only thing that needs to be in the batch file is

@echo off
cls
del C:\some\directory\*.bkf

And the delete path can also be sent to this batch script as an argument so that the directory is changeable.

CheeseConQueso
  • 5,831
  • 29
  • 93
  • 126
1

I ended up just writing an EXE that accepts parameters and scheduling that. Unfortunately the other solutions didn't have the flexibility needed.

Joe Phillips
  • 49,743
  • 32
  • 103
  • 159
0

have you looked into forfiles.exe?

http://blog.stevienova.com/2007/02/27/forfiles-delete-files-older-than-x-amount-of-days/

phill
  • 13,434
  • 38
  • 105
  • 141