How to delete multiple files using FSO and wildcards...
-
I am trying to use the file system object to delete a batch of files, based on the name of the file. E.g. I have files in the format: file17_68.asp The first number signifies a category, the second is an individual ID. What I want to be able to do is delete files that belong to the one category. What I've tried is: *start code snippet* set fso = Server.Createobject("Scripting.FileSystemObject") fname = "\files\file" & EditCatID & "*.asp" fso.DeleteFile(Server.MapPath(fname)) set fso = nothing **end code snippet** I thought the wildcard (*) would mean that all files beginning file17 would then be successfully deleted. This fails to work - so does anyone have any brilliant and cunning ideas? or suggestions why this doesn't work?
-
I am trying to use the file system object to delete a batch of files, based on the name of the file. E.g. I have files in the format: file17_68.asp The first number signifies a category, the second is an individual ID. What I want to be able to do is delete files that belong to the one category. What I've tried is: *start code snippet* set fso = Server.Createobject("Scripting.FileSystemObject") fname = "\files\file" & EditCatID & "*.asp" fso.DeleteFile(Server.MapPath(fname)) set fso = nothing **end code snippet** I thought the wildcard (*) would mean that all files beginning file17 would then be successfully deleted. This fails to work - so does anyone have any brilliant and cunning ideas? or suggestions why this doesn't work?
It works fine, but MapPath cannot map file names with wildcards. You need to map the directory first and then add a file name, like this:
set fso = Server.Createobject("Scripting.FileSystemObject")
fso.DeleteFile Server.MapPath("\files\") & "\file" & EditCatID & "*.asp"
set fso = nothingPhilip Patrick Web-site: www.saintopatrick.com "Two beer or not two beer?" Shakesbeer Need ASP hosting? Check out 123HostNow.com