473,407 Members | 2,306 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

problem with File.Delete

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
Jul 15 '08 #1
6 1698
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

On Jul 15, 2:24*pm, "Ben" <b...@sdf.sfswrote:
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
Jul 15 '08 #2
"Ben" <be*@sdf.sfswrote in message
news:eu**************@TK2MSFTNGP04.phx.gbl...
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?
The File.Delete method does not support wildcards. Therefore, you need to
instantiate a collection of files that you want to delete, and then iterate
through them and delete them individually...

http://msdn.microsoft.com/en-us/library/cc148994.aspx
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Jul 15 '08 #3
Ben
Thanks
(one explanation, in this case, those of Booghost, was enough ... Redundant
information must be avoided, no?)

"Mark Rae [MVP]" <ma**@markNOSPAMrae.netschreef in bericht
news:uu**************@TK2MSFTNGP02.phx.gbl...
"Ben" <be*@sdf.sfswrote in message
news:eu**************@TK2MSFTNGP04.phx.gbl...
>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?

The File.Delete method does not support wildcards. Therefore, you need to
instantiate a collection of files that you want to delete, and then
iterate through them and delete them individually...

http://msdn.microsoft.com/en-us/library/cc148994.aspx
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Jul 16 '08 #4
"Ben" <kn*@shdv.sdwrote in message
news:%2****************@TK2MSFTNGP06.phx.gbl...

[top-posting corrected]
>>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?

The File.Delete method does not support wildcards. Therefore, you need to
instantiate a collection of files that you want to delete, and then
iterate through them and delete them individually...

http://msdn.microsoft.com/en-us/library/cc148994.aspx

(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...?
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Jul 16 '08 #5
Ben
ok!

"Mark Rae [MVP]" <ma**@markNOSPAMrae.netschreef in bericht
news:uQ**************@TK2MSFTNGP02.phx.gbl...
"Ben" <kn*@shdv.sdwrote in message
news:%2****************@TK2MSFTNGP06.phx.gbl...

[top-posting corrected]
>>>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?

The File.Delete method does not support wildcards. Therefore, you need
to instantiate a collection of files that you want to delete, and then
iterate through them and delete them individually...

http://msdn.microsoft.com/en-us/library/cc148994.aspx

(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...?
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Jul 16 '08 #6
I too detest top posting, but not as much as self appointed internet police
;)

Marc
Jul 16 '08 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Jobs | last post by:
Hello All, I want to delete all files in a directory. I am making a backup copy of all files in the directories say c:\abc by reading and writing to a file. After making a backup copy I want to...
4
by: Max | last post by:
Hello. This is the first time I've posted to a newsgroup, and I do this because I'm in desperate need of help. I'm working a user management system, and when I activate a user that has registered...
2
by: Chris Bolus | last post by:
I'm a teacher using MS Access on an RMConnect 2.4 network. On some workstations both I and my students sometimes get an error message when attempting to insert a command button on a form which...
13
by: Bob Darlington | last post by:
I have a repair and backup database routine which runs when a user closes down my application. It works fine in my development machine, but breaks on a client's at the following line: If...
4
by: Nagachandra Sekhar Grandhi | last post by:
I am facing a problem with OpenFileDialog. It is as follows. I opened OpenFileDialog dialog box and selected a folder in it. After selecting the folder when i tried to delete the same folder in...
4
by: Saso Zagoranski | last post by:
Hi! Here is what I'm trying to do: I have created a UserControl named PictureView. It holds all the images in one directory in the Bitmap images variable. The selected image is displayed in...
3
by: Daniel Billingsley | last post by:
Today I went to compile a solution I've been working on for months. I've been off most of the last few months, so there's been a gap in the work, but I did compile it a few times earlier this...
8
by: George | last post by:
VB.net 2003 standard, XP windows home edition. Installed first application OK today. When I removed the application via Control Panel, there were no problems and the app folders were deleted. ...
2
by: Brad | last post by:
I have a web .Net app which sends emails with attachments. After the email is sent I clean up aftermyself and delete the attachments from disk. In upgrading to .Net 2 I changed the email logic...
2
by: andrescasta | last post by:
Hello, i have a problem when i try to delete a file that i recently uploaded. To upload, i used the FileUpload, when i receive the file, i save it in a directory inside the virtual application...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.