With an instance of a DirectoryInfo class in hand that references the directory you want to make hidden in, you need only examine/set the Attributes property with the FileAttributes.Hidden flag ala:

            DirectoryInfo di = new DirectoryInfo(@"C:\SomeDirectory");

            //See if directory has hidden flag, if not, make hidden

            if( (di.Attributes & FileAttributes.Hidden) != FileAttributes.Hidden)

            {

                //Add Hidden flag

                di.Attributes = di.Attributes | FileAttributes.Hidden;

            }

 

            //See if directory has hidden flag, if not, make visible

            if ((di.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden)

            {

                //Remove Hidden flag

                di.Attributes = di.Attributes ^ FileAttributes.Hidden;
            }

Posted by penguindori