By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,016 Members | 2,297 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,016 IT Pros & Developers. It's quick & easy.

deleting all files inside a folder

P: n/a
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
Share this Question
Share on Google+
5 Replies


P: n/a
"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

P: n/a
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

P: n/a
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

P: n/a
"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

P: n/a
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.