Creating a hidden directory & file!

Hi,

Can anyone please tell me how to create a directory and a file as hidden using C#. It would be great if you could provide me with the code.

Thanks & Regards,
Frenz



Answer this question

Creating a hidden directory & file!

  • DVdR

    This is a two step process for each item: Create the item, update its attributes.

    public void CreateDirectory ( string name, bool hidden )
    {
    if (!Directory.Exists(name))
    {
    //Doesn't create any parent directories that might be missing
    Directory.CreateDirectory(name);
    };

    DirectoryInfo dir = new DirectoryInfo(name);

    if (hidden)
    dir.Attributes |= FileAttributes.Hidden;
    else
    dir.Attributes &= ~FileAttributes.Hidden;
    }

    Similar process for files but instead using File and FileInfo classes.

    Michael Taylor - 5/11/06


  • Creating a hidden directory & file!