468,287 Members | 1,946 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,287 developers. It's quick & easy.

deleting all files inside a folder

Hey All,

Could somebody please tell me how to delete all files inside a folder using
Visual Basic .NET 2003?
(I know this may be basic, but forgive me, im newbie)
Thanks in advance,

'Meshuggah'
Feb 18 '06 #1
5 2425
"Meshuggah" <no*****@please.thanks> wrote in
news:43***********************@news.wanadoo.nl:
Hey All,

Could somebody please tell me how to delete all files inside a folder
using Visual Basic .NET 2003?
(I know this may be basic, but forgive me, im newbie)
Thanks in advance,

'Meshuggah'


Just a quick idea, one newbie to another...

Couldn't you:

Dim DirFiles As String() = System.IO.Directory.GetFiles(DirectoryPath)

Dim A As Integer
For A = 0 To String.GetUpperBound(0)
System.IO.File.Delete(String(A))
Next

Or I could be wrong... I've never done a routine similar to this myself,
and GetFiles could return only the filename, in which case the code in the
for/next loop would be

System.IO.File.Delete(DirectoryPath & String(A))

The Confessor
Feb 18 '06 #2
Dim d As System.IO.Directory, f As System.IO.File, i As Int32

Dim s() As String = d.GetFiles("C:\Test")

For i = 0 To s.GetUpperBound(0)

f.Delete(s(i))

Next

--
Get a powerful web, database, application, and email hosting with KJM
Solutions
http://www.kjmsolutions.com

"Meshuggah" <no*****@please.thanks> wrote in message
news:43***********************@news.wanadoo.nl...
Hey All,

Could somebody please tell me how to delete all files inside a folder
using
Visual Basic .NET 2003?
(I know this may be basic, but forgive me, im newbie)
Thanks in advance,

'Meshuggah'

Feb 18 '06 #3
Thanks a lot!
Could you perhaps also tell me how to delete files of only 1 type (like jpg)
from a folder?

--
'Meshuggah'

"vbnetdev" <vb******@community.nospam> wrote in message
news:OW**************@TK2MSFTNGP09.phx.gbl...
Dim d As System.IO.Directory, f As System.IO.File, i As Int32

Dim s() As String = d.GetFiles("C:\Test")

For i = 0 To s.GetUpperBound(0)

f.Delete(s(i))

Next

--
Get a powerful web, database, application, and email hosting with KJM
Solutions
http://www.kjmsolutions.com

"Meshuggah" <no*****@please.thanks> wrote in message
news:43***********************@news.wanadoo.nl...
Hey All,

Could somebody please tell me how to delete all files inside a folder
using
Visual Basic .NET 2003?
(I know this may be basic, but forgive me, im newbie)
Thanks in advance,

'Meshuggah'


Feb 18 '06 #4
"Meshuggah" <no*****@please.thanks> schrieb:
Could somebody please tell me how to delete all files inside a folder
using
Visual Basic .NET 2003?


\\\
Imports System.IO
....
For Each FileName As String In Directory.GetFiles("C:\foo")
Kill(FileName)
Next FileName
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Feb 18 '06 #5
Private Sub DeleteFiles (sDirectory As String, sFilter As String)
Try
For Each strFile As String In Directory.GetFiles(sDirectory,
sFilter)
IO.File.Delete(strFile)
Next
Catch Ex As Exception
' Normally File Already Open Error or FileIOPermission Error
MessageBox.Show(Ex.ToString)
End Try
End Sub

Usage:
-------

DeleteFiles("C:\Some Directory", "*.jpg")

------------------------------------------

I hope this helps,

Crouchie1998
BA (HONS) MCP MCSE
Feb 19 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Martin Bischoff | last post: by
4 posts views Thread by clintonG | last post: by
2 posts views Thread by Meshuggah | last post: by
5 posts views Thread by Sandeep Singh Sekhon | last post: by
3 posts views Thread by Kimera.Kimera | last post: by
2 posts views Thread by MrBee | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.