Wednesday, January 9, 2013

VB Script to delete only .txt file(S)

VB Script to delete only .txt file(S) in the directory only if Date Last Modified is greater than 10 days.


Sub DeleteTxtFile()

Dim Directory
Dim Modified
Dim Files
Dim File

Set fso = CreateObject("Scripting.FileSystemObject")

Set Directory = fso.GetFolder("D:\test")

Set Files = Directory.Files

For Each folderIdx In Files

    If Right(folderIdx, 4) = ".txt" Then
        If DateDiff("D", folderIdx.DateLastModified, Now) > 10 Then folderIdx.Delete
    End If
   
Next

End Sub

No comments:

Post a Comment

Code Formater

Paste Here Your Source Code
Source Code Formatting Options
1) Convert Tab into Space :
2) Need Line Code Numbering :
3) Remove blank lines :
4) Embeded styles / Stylesheet :
5) Code Block Width :
6) Code Block Height :
7) Alternative Background :
Copy Formatted Source Code
 
Preview Of Formatted Code