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: 1179
  • Last Modified:

Schedule delete for files older than

Hello,

I have a folder in windows 2008 server that has some log files generated every 5 minutes.

How can I make schedule auto delete for files older than 3 hours.

Thanks

0
zaki100
Asked:
zaki100
  • 3
  • 2
1 Solution
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
you did not yet google around for that, did you :)
http://www.google.lu/search?hl=en&client=firefox-a&rls=org.mozilla%3Aen-US%3Aofficial&hs=LZ8&q=vbscript+delete+files+older+than+x+hours&btnG=Search

anyhow, you need 2 parts:
? create a vbscript (easiest for me, at least), that deletes files older than X in a certain folder (+ subfolders, if needed)
? create a windows scheduled task to run that vbscript file (cscript yourscript.vbs)

0
 
zaki100Author Commented:
Thank you for your help

I have tried some of them but it deletes all files in a folder regardless file date time.

I need a direct tested answer using bat file

Reagrds

Zaki
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
well...

let me start with my .vbs file:
Dim Fso
Dim Directory
Dim Folders
Dim SubFolder
Dim Modified
Dim Files
 
Set Fso = CreateObject("Scripting.FileSystemObject")
 
Set Directory = Fso.GetFolder("D:\backupSQL")
Set Folders = Directory.SubFolders
 
for each SubFolder in Folders
  Set Files = SubFolder.Files
 
  For Each Modified in Files
 
    If DateDiff("D", Modified.DateLastModified, Now) > 2 Then 
      Modified.Delete
    End If
  next   
 
Next

Open in new window

0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
the matching .bat file contains this:

cscript d:\backupSQL\delete_old_files.vbs

Open in new window

0
 
zaki100Author Commented:
Thank you for your help

I will try and let you know.

Regards

Zaki
0

Featured Post

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now