C# 创建隐藏文件夹

C# 创建隐藏文件夹,c#,.net,filesystems,C#,.net,Filesystems,是否有任何方法可以从c#中以编程方式在存储设备上创建(我猜是访问)隐藏文件夹?是的,您可以。创建一个普通的目录,然后设置它的属性。例如 DirectoryInfo di = new DirectoryInfo(@"C:\SomeDirectory"); //See if directory has hidden flag, if not, make hidden if ((di.Attributes & FileAttributes.Hidden) != FileAttributes.

是否有任何方法可以从c#中以编程方式在存储设备上创建(我猜是访问)隐藏文件夹?

是的,您可以。创建一个普通的目录,然后设置它的属性。例如

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;    
}

From.

编码以仅获取根文件夹路径

就像我们有C:/Test一样/ C:/Test/Abc C:/Test/xyz C:/Test2/ C:/Test2/mnp

它将返回根文件夹路径,即。 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++;                    
            }
int索引=0;
while(索引<一次计数)
{
My obj=lst[索引];
lst.RemoveAll(a=>a.Path.StartsWith(obj.Path));
一级插入(索引,obj);
索引++;
}

重新标记,因为这不是C语言特有的问题,没有解释的代码转储很少有用。请为这个添加一些上下文。(另外,您可能有兴趣知道您已经回答了一篇超过6年的帖子……)现在您是Google.If子句上的第一个结果,可以将If(!di.Attributes.hasblag(FileAttributes.Hidden))缩减为
If(!di.Attributes.hasblag(FileAttributes.Hidden))
string path = @"c:\folders\newfolder"; // or whatever 
if (!System.IO.Directory.Exists(path)) 
{ 
    DirectoryInfo di = Directory.CreateDirectory(path); 
    di.Attributes = FileAttributes.Directory | FileAttributes.Hidden; 
}
CreateHiddenFolder(string name)  
{  
  DirectoryInfo di = new DirectoryInfo(name);  
  di.Create();  
  di.Attributes |= FileAttributes.Hidden;  
}  
            int index = 0;
            while (index < lst.Count)
            {
                My obj = lst[index];
                lst.RemoveAll(a => a.Path.StartsWith(obj.Path));
                lst.Insert(index, obj );
                index++;                    
            }