Delete File and Folder
Form1.vb
Dim myFolder As String
Dim appSet As New System.Configuration.AppSettingsReader
myFolder = appSet.GetValue("folder", GetType(String))
For Each myDir As String In Directory.GetDirectories(myFolder)
Try
Directory.Delete(myDir, True)
Catch ex As Exception
Continue For
End Try
Next
For Each myFile As String In Directory.GetFiles(myFolder)
Try
File.Delete(myFile)
Catch ex As Exception
Continue For
End Try
Next
App.config
<appSettings>
<add key="folder" value="C:\TEST\New folder (2)\New folder"/>
</appSettings>
Dim myFolder As String
Dim appSet As New System.Configuration.AppSettingsReader
myFolder = appSet.GetValue("folder", GetType(String))
For Each myDir As String In Directory.GetDirectories(myFolder)
Try
Directory.Delete(myDir, True)
Catch ex As Exception
Continue For
End Try
Next
For Each myFile As String In Directory.GetFiles(myFolder)
Try
File.Delete(myFile)
Catch ex As Exception
Continue For
End Try
Next
App.config
<appSettings>
<add key="folder" value="C:\TEST\New folder (2)\New folder"/>
</appSettings>
Comments
Post a Comment