Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I'm trying to create a batch file that will delete a files by a certain name. The files will all be similar to this. a20081010.txt or a20081011.txt or a20081012.txt... etc. Then if the files are older then 30 days for datemodified then I want to delete the file. Here is what I have so far.
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder("C:\Documents and Settings\Username\My Documents\batch file\test")
For Each efile in objFolder.Files
If exist *.txt Then
If DateDiff("d",eFile.DateLastModified,Now) >= 30 Then
objFSO.DeleteFile(eFile)
End If
Next

Time to go over your thread's title.
Batch file delete file by file name
| | | |
+--+---+ +---+----+
| |
+----+ Not by
| file's
VBScript <> Batch name.Let's try this again, shall we?
Aside from the line If exist *.txt Then, it's a perfectly valid script. If you're looking to only delete .txt files, I suggest you get rid of the first If, and change the second If to this:
If LCase(objFSO.GetExtensionName(efile)) = "txt" And DateDiff("d",eFile.DateLastModified,Now) >= 30 Then

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |