Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need to kill old files ending with a wildcard name

Status
Not open for further replies.

newcoder54

Technical User
Jul 2, 2002
46
0
0
US
I have a function that works fine to kill files over 2 days old but wish I could kill files that have file names ending with, for example, a sequence number.

For example I want the function to kill files like this

C:\My Documents\Johnson datafile-544.doc

but not to kill C:\My Documents\Johnson Datafile.doc

Any ideas,

Here is what works and needs your great ideas!

Thanks, Larry

Function KillOldFiles()
Dim MyStamp As Date

MyStamp = FileDateTime("c:\My Documents\Johnson data file number-544.doc")
If MyStamp < (Now() - 2) Then

Kill "c:\My Documents\Johnson data file number* doc"
'
End If

End Function
 
How about something like this:

With Application.FileSearch
.NewSearch
.LookIn = “C:\BlahBlahBla”
.SearchSubFolders = True
.FileName = "??Bla*.* "
.MatchTextExactly = True
End With

With Application.FileSearch
For I = 1 To .FoundFiles.Count
Kill (.FoundFiles(I))
Next I
End With

Of course, the .filename would need to be corrected to what you need, also the .lookin, but I think this is what you are after.

ChaZ

"When religion and politics ride in the same cart...the whirlwind follows."
Frank Herbert
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top