본문 바로가기
Visual Basic .NET/Directory & File

How to use Directory Class to make a new directory

by edupicker(체르니) 2008. 6. 30.

How to use Directory Class to make a new directory

 

Public NotInheritable Class Directory

          Inherits System.IO

 

The Directory class is a static class, which means you do not have to create an instance of a Directory class object in order to use the class methods.

You just use the class.

The following program, I used to directory class Exists method to determine if the specified directory exists. If the directory does not exist, the program will create the directory.

 

The core code :

 

Try

      Dim createDirString As String

 

       'used ltrim, rtrim function to remove blank, and restricted D drive. 

       createDirString = "D:\" & LTrim(RTrim(txtDirectory.Text))

 

       If (Directory.Exists(createDirString)) Then

          txtResult.Text = createDirString & "is already existed"

          

       Else

          Directory.CreateDirectory(createDirString)

          txtResult.Text = createDirString & "is normally created"

       End If

 

Catch ex As Exception

       txtResult.Text = "Error occurred while Creating Directory" & ex.Message

End Try

 

Execution:

사용자 삽입 이미지

have a nice night!

'Visual Basic .NET > Directory & File' 카테고리의 다른 글

how to delete, move directory  (0) 2008.06.30