Creating hidden folders

前端 未结 5 1058
-上瘾入骨i
-上瘾入骨i 2020-12-13 17:52

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

相关标签:
5条回答
  • 2020-12-13 17:53
    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; 
    }
    
    0 讨论(0)
  • 2020-12-13 18:04
    string path = @"c:\folders\newfolder"; // or whatever 
    if (!System.IO.Directory.Exists(path)) 
    { 
        DirectoryInfo di = Directory.CreateDirectory(path); 
        di.Attributes = FileAttributes.Directory | FileAttributes.Hidden; 
    }
    

    From here.

    0 讨论(0)
  • 2020-12-13 18:06

    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;    
    }
    
    0 讨论(0)
  • 2020-12-13 18:06
    CreateHiddenFolder(string name)  
    {  
      DirectoryInfo di = new DirectoryInfo(name);  
      di.Create();  
      di.Attributes |= FileAttributes.Hidden;  
    }  
    
    0 讨论(0)
  • 2020-12-13 18:18

    Code to get only Root folders path.

    Like If we have C:/Test/ C:/Test/Abc C:/Test/xyz C:/Test2/ C:/Test2/mnp

    It will return root folders path i.e. C:/Test/ C:/Test2/

                int index = 0;
                while (index < lst.Count)
                {
                    My obj = lst[index];
                    lst.RemoveAll(a => a.Path.StartsWith(obj.Path));
                    lst.Insert(index, obj );
                    index++;                    
                }
    
    0 讨论(0)
提交回复
热议问题