You are hereVBScript: Delete files older than x days

VBScript: Delete files older than x days


By edwin - Posted on 27 May 2009

The example below simply deletes any files older than 2 days from the root of the F:\Files directory.

  1. Dim Fso
  2. Dim Directory
  3. Dim Modified
  4. Dim Files
  5.  
  6. Set Fso = CreateObject("Scripting.FileSystemObject")
  7. Set Directory = Fso.GetFolder("F:\Files")
  8. Set Files = Directory.Files
  9.  
  10. For Each Modified in Files
  11.  
  12. If DateDiff("D", Modified.DateLastModified, Now) > 2 Then Modified.Delete
  13.  
  14. Next

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <blockquote> <img> <span>
  • Lines and paragraphs break automatically.
  • Pairs of<blockquote> tags will be styled as a block that indicates a quotation.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>. The supported tag styles are: <foo>, [foo].
  • Images can be added to this post.

More information about formatting options