Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating hidden folders

Is there any way that I can programmatically create (and I guess access) hidden folders on a storage device from within c#?

like image 693
TK. Avatar asked Sep 18 '08 13:09

TK.


People also ask

What does hiding a folder do?

Choosing to hide just the folder will hide that folder from being seen in File Explorer, but won't hide the actual files contained within. The other option is used to hide both the folder and all the data inside, including any subfolders and subfolder files.

How do I permanently hide a folder?

It would have to be surgically removed from a boot disk. So no worries there. Make sure System files are hidden only in File Explorer > View > Options > Change Folder and Search Options > View > check Hide Protected Operating System Files, approve security box, Apply, Save.


2 Answers

using System.IO;   string path = @"c:\folders\newfolder"; // or whatever  if (!Directory.Exists(path))  {  DirectoryInfo di = Directory.CreateDirectory(path);  di.Attributes = FileAttributes.Directory | FileAttributes.Hidden;  } 
like image 133
Tom Ritter Avatar answered Sep 16 '22 21:09

Tom Ritter


Yes you can. Create the directory as normal then just set the attributes on it. E.g.

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 |= FileAttributes.Hidden;     } 
like image 28
Mark Ingram Avatar answered Sep 20 '22 21:09

Mark Ingram