Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VB.Net Delete all files in folder

Tags:

vb.net

I am trying to delete all files from single folder in VB.Net but to keep that folder.

As far as i know, i can delete files by this way:

Dim heart17 As System.IO.FileInfo = New IO.FileInfo("path")
heart17.Delete()

And it works, but i need to empty a whole folder.

The folder path is

C:\Users\username\Desktop\Games.

I've read this question, but it doesn't work for me (it has some errors or i did something wrong).

like image 335
Stefan Đorđević Avatar asked May 03 '16 17:05

Stefan Đorđević


3 Answers

This will help you to delete all files in the specified directory you can specify the search pattern to delete files that satisfies the pattern; some possible search patterns are:

  • "*.jpg" - selects all jpg files.

  • "*.txt" - selects all text files.

  • "*123.txt" selects all text files whose name ends with 123

Dim directoryName As String = "your path here"
For Each deleteFile In Directory.GetFiles(directoryName ,"*.*",SearchOption.TopDirectoryOnly)
    File.Delete(deleteFile)
Next
like image 114
sujith karivelil Avatar answered Sep 25 '22 01:09

sujith karivelil


What about

FileSystem.Kill ("c:\path\*.*")
FileSystem.Kill ("c:\path\*.jpg")

etc.?

like image 27
Stefan Meyer Avatar answered Sep 23 '22 01:09

Stefan Meyer


IO.Directory.Delete(

"true" means blow everything away: all sub-dirs. and files

like image 36
Doug Null Avatar answered Sep 26 '22 01:09

Doug Null