|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
deleting all files inside a folderHey 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 -- Show quoteHide quoteGet 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' > Thanks a lot!
Could you perhaps also tell me how to delete files of only 1 type (like jpg) from a folder? -- Show quoteHide quote'Meshuggah' "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' >> > > 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
Show quote
Hide quote
"Meshuggah" <noemail@please.thanks> wrote in Just a quick idea, one newbie to another...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' > > > 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 "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/> |
|||||||||||||||||||||||