Thursday, May 26, 2016

Directories VB.net




Hey guys. Today I will do a very simple tutorial to explain how to crte and delete directories. So, let´s go! Maybe this is a stupid tutorial but is just for you understand the basic of crting folders and subfolders, and also how to delete it.First open your Visual Studio and Crte a New Project using Visual Basic. Rename it if you want. Add two textbox and two buttons. The first button, rename it as “Crte” and the second one as “Delete”.
Crte Directory
Double-Click in the button named as “Crte”Private Sub Button1_Click(sender AsSystem.Object, e AsSystem.EventArgs) HandlesButton1.Click Try System.IO.Directory.CrteDirectory(TextBox1.Text) chex As Exception MsgBox(ex.Message, vbCritical + vbOKOnly, "Error") End Try End Sub
Delete Directory
Double-Click in the button named as “Delete”Private Sub Button2_Click(sender AsSystem.Object, e AsSystem.EventArgs) HandlesButton2.Click Try System.IO.Directory.Delete(TextBox2.Text) chex As Exception MsgBox(ex.Message, vbCritical + vbOKOnly, "Error") EndTry EndSub

Check if a directory exists
But to prevent errors here you first you should check if the directory exists like in next example:Private Sub Button2_Click(sender AsSystem.Object, e AsSystem.EventArgs) HandlesButton2.Click IfSystem.IO.Directory.Exists(TextBox2.Text) Then Try System.IO.Directory.Delete(TextBox2.Text) ch ex As Exception MsgBox(ex.Message, vbCritical + vbOKOnly, "Error") End Try EndIf EndSub

No comments:

Post a Comment