How to create hidden property directory?

  • Thread starter Thread starter YXQ
  • Start date Start date
How to create hidden property directory using Directory.CreateDirectory?
Thank you

Hi,
To create a hidden folder, you can use DirectoryInfo class as follows:

' Specify path of folder in constructor
Dim dir As New System.IO.DirectoryInfo("c:\myhidden")

' Create folder
dir.Create()

' That property makes the job
dir.Attributes = IO.FileAttributes.Hidden


Hope this helps,

Onur Güzel
 
Thank you, but how to know the folder has been created successfully? my code
below will not work, thank you

////////////////////////////////////////////////////////////////
Dim dir As New System.IO.DirectoryInfo("m:\myhidden")
dir.Create()

dir.Attributes = IO.FileAttributes.Hidden
' Create folder

Do Until dir.Attributes = IO.FileAttributes.Hidden
Application.DoEvents()
Loop
///////////////////////////////////////////////////////////
 
Thank you, but how to know the folder has been created successfully? my code
below will not work, thank you

////////////////////////////////////////////////////////////////
       Dim dir As New System.IO.DirectoryInfo("m:\myhidden")
        dir.Create()

        dir.Attributes = IO.FileAttributes.Hidden
        ' Create folder

        Do Until dir.Attributes = IO.FileAttributes.Hidden
            Application.DoEvents()
        Loop
///////////////////////////////////////////////////////////

Calling dir.Create method will create folder, then you're ready to set
its attirbute as Hidden. If you want to check whether operation is
successful, you can use the code in a Try-Catch block and handling
exceptions in Catch block. However, i'm not fully sure what you want,
if you're referring to an existing directory to make it hidden, remove
Create method just use:

Dim dir As New System.IO.DirectoryInfo("c:\myhidden")
dir.Attributes = IO.FileAttributes.Hidden

Plus, it depends on what you want to achieve exaclty, for instance, to
make all files hidden inside that directory you must use FileInfo
class in a loop by iterating.

Onur Güzel
 
Thank you for your help.

Onur Güzel said:
Calling dir.Create method will create folder, then you're ready to set
its attirbute as Hidden. If you want to check whether operation is
successful, you can use the code in a Try-Catch block and handling
exceptions in Catch block. However, i'm not fully sure what you want,
if you're referring to an existing directory to make it hidden, remove
Create method just use:

Dim dir As New System.IO.DirectoryInfo("c:\myhidden")
dir.Attributes = IO.FileAttributes.Hidden

Plus, it depends on what you want to achieve exaclty, for instance, to
make all files hidden inside that directory you must use FileInfo
class in a loop by iterating.

Onur Güzel
 
Back
Top