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

FSO delete file if exists

Status
Not open for further replies.

123ASP

MIS
Nov 2, 2002
239
US
hi, I have 3 text files a.txt. & b.txt & c.txt
when I check if files exist by putting * it does not work, but when I specify a.txt it work.
Does that mean that I cannot check if all files exists *.txt

Dim objFSO
Set objFSO = Server.CreateObjectScripting.FileSystemObject")
If objFSO.FileExists("C:\a\letters\*.txt") then
objFSO.DeleteFile "C:\a\letters\*.txt",False
response.Write "deleted all files"
response.Write &quot;<BR>&quot;
else
response.Write &quot; No file found to be deleted&quot;
end if
Set objFSO = Nothing

thanks,
Al
 
No, you cannot specify a wildcard because that function is designed to check a single filename, not a collection of files. You could do a loop to check for all of them, looping from the ascii code for a to z using the chr function to generate the filename from the ascii code.

-Tarwn 01010100 01101001 01100101 01110010 01101110 01101111 01101011 00101110 01100011 01101111 01101101
29 3K 10 3D 3L 3J 3K 10 32 35 10 3E 39 33 35 10 3K 3F 10 38 31 3M 35 10 36 3I 35 35 10 3K 39 3D 35 10 1Q 19
Get better results for your questions: faq333-2924
Frequently Asked ASP Questions: faq333-3048
 
Why check if you're only going to delete them? Just do a wild-card delete and be done.

Or am I missing something?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top