Home All Groups Group Topic Archive Search About

deleting all files inside a folder

Author
18 Feb 2006 6:48 PM
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'

Author
18 Feb 2006 6:57 PM
vbnetdev
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



Show quoteHide quote
"Meshuggah" <noemail@please.thanks> wrote in message
news:43f76c1c$0$33144$dbd49001@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'
>
Author
18 Feb 2006 7:12 PM
Meshuggah
Thanks a lot!
Could you perhaps also tell me how to delete files of only 1 type (like jpg)
from a folder?

--
'Meshuggah'

Show quoteHide quote
"vbnetdev" <vbnetdev@community.nospam> wrote in message
news:OWZ1o0LNGHA.1312@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" <noemail@please.thanks> wrote in message
> news:43f76c1c$0$33144$dbd49001@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'
>>
>
>
Author
19 Feb 2006 10:42 AM
msnews.microsoft.com
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
Author
18 Feb 2006 6:58 PM
The Confessor
Show quote Hide quote
"Meshuggah" <noemail@please.thanks> wrote in
news:43f76c1c$0$33144$dbd49001@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
Author
18 Feb 2006 9:05 PM
Herfried K. Wagner [MVP]
"Meshuggah" <noemail@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/>