problem with File.Delete

  • Thread starter Thread starter Ben
  • Start date Start date
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
 
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
 
Thanks
(one explanation, in this case, those of Booghost, was enough ... Redundant
information must be avoided, no?)
 
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...?
 
Back
Top