Computing.Net > Forums > Programming > Batch file delete file by file name

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Batch file delete file by file name

Reply to Message Icon

Name: GMmuscle86
Date: August 18, 2008 at 12:07:52 Pacific
OS: XP
CPU/Ram: 2Gs
Product: IBM ThinkPad
Comment:

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



Sponsored Link
Ads by Google

Response Number 1
Name: Razor2.3
Date: August 18, 2008 at 17:53:06 Pacific
Reply:

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


0
Reply to Message Icon

Related Posts

See More







Post Locked

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


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Batch file delete file by file name

Batch File deleting files by date? www.computing.net/answers/programming/batch-file-deleting-files-by-date/15581.html

Batch file for deletion of backups www.computing.net/answers/programming/batch-file-for-deletion-of-backups-/15443.html

batch file - deletes folders & more www.computing.net/answers/programming/batch-file-deletes-folders-amp-more/9353.html