problem with File.Delete

B

Ben

Hi,

i want to delete all excel files together in a specific directory. I tried
this but the syntax is wrong: File.Delete(Server.MapPath("~/excel/" &
"*.xls"))

Can somebody tell me the right syntax?
Thanks
Ben
 
B

BooGhost

Ben,
If you were to look at the documentation for System.IO.File.Delete()
you'd see that it takes a path to the file you want gone. Path's can
not include wildcards.

You want to do something like:
Dim tFilePath As String = String.Empty

For Each tFilePath In Directory.GetFiles(Server.MapPath("whatever"),
"*.xls")
File.Delete(tFilePath)
Next

You should be aware of a small (I think) bug in the file matching
algorithm Directory.GetFiles() uses. "*.xls" will match all files
who's extension begins with xls. This includes xls, xlsx, xlsa,
xlsux, etc.

-Boo
 
B

Ben

Thanks
(one explanation, in this case, those of Booghost, was enough ... Redundant
information must be avoided, no?)
 
B

Ben

ok!

Mark Rae said:
[top-posting corrected]
(one explanation, in this case, those of Booghost, was enough ...
Redundant information must be avoided, no?)

BooGhost's reply hadn't appeared on the newsserver when I posted my
reply - there is often a time-lag in these things...

How about you don't top-post next time...?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,175
Latest member
Vinay Kumar_ Nevatia
Top