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>

Comments

Popular posts from this blog

การตั้งเวลาระหว่าง Server และ Client

วิธีตั้งค่า NTP บน Primary Domain Controller

Installation and Run Node.JS on IIS