deleting all files inside a folder

  • Thread starter Thread starter Meshuggah
  • Start date Start date
M

Meshuggah

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'
 
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
 
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
 
Thanks a lot!
Could you perhaps also tell me how to delete files of only 1 type (like jpg)
from a folder?
 
Meshuggah said:
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
///
 
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
 
Back
Top