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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

deleting files

Status
Not open for further replies.

mrnez

Technical User
Sep 11, 2002
37
GB
Hello I have the following VB script which deletes all files in a given folder older than 1 hour.

However I want it to only delete files with that match the criteria css*.*

I can't figure out how to do it.

Any help would be most appreciated

Thanks

Richard
 
Hi Richard,

since you did not post your script, here my suggestion:
Code:
Dim fso
Dim flFolder, flFile

Set fso = CreateObject("scripting.filesystemobject")
Set flFolder = fso.GetFolder("c:\sandbox")
For Each file In flFolder.files
 If InStr(file.name, "css") = 1 (maybe AND Instr(file.name, ".") >1 )Then
 	fso.DeleteFile(file)
 End if
Next

Works for me.

Hope this helps.

Cattys
 
oops should have posted the script, I am too tired ;)

Here you go, I will look at your solution too.

Thanks

Dim fso, fol, fil
Set fso = CreateObject("Scripting.FileSystemObject")
Set fol = fso.GetFolder("c:\richard")
For Each fil In fol.Files
If DateDiff("n", fil.DateLastModified, Now) > Then fil.Delete
Next
 
Sorry it really is a bad day !! I missed the time constraint out of the script.

Dim fso, fol, fil
Set fso = CreateObject("Scripting.FileSystemObject")
Set fol = fso.GetFolder("c:\richard")
For Each fil In fol.Files
If DateDiff("n", fil.DateLastModified, Now) > 60 Then fil.Delete
Next

I am just looking at your solution at the moment to try and combine it with mine

Thanks

Richard,
 
ok, this should work for you:
Code:
Dim fso
Dim flFolder, flFile

Set fso = CreateObject("scripting.filesystemobject")
Set flFolder = fso.GetFolder("c:\sandbox")
For Each flfile In flFolder.files
 If InStr(flfile.name, "css") = 1 And datediff("n",flFile.datelastmodified, Now)> 60 Then
 	fso.DeleteFile(file)
 	
 End if
 Next
 
hehe, maybe you should take a nap?
Just a thought :)

here it is around 1pm at the moment.
 
It's 1pm here but after working all the hours god sends on a new project I only had 3 hours sleep and am feeling tired.

whereabouts are you ?

PS It works Thanks for all the help I will eventually get the hang of this scripting.

Richard
 
Here is Germany, Munich,
Where do you come from?
Its rare that I meet someone from around my time zone here.
Mostly they come from the US.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top