创建隐藏文件夹
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;
}
第一个结果现在你是谷歌的第一个结果。 – 2008-09-18 13:12:31
一个C#语言特定的问题 – KDecker 2015-08-25 19:11:26
是的,你可以。照常创建目录,然后在其上设置属性。例如。
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;
}
如果子句可以简化为`if(!di.Attributes.HasFlag(FileAttributes.Hidden))` – schoetbi 2017-04-05 12:24:52
string path = @"c:\folders\newfolder"; // or whatever
if (!System.IO.Directory.Exists(path))
{
DirectoryInfo di = Directory.CreateDirectory(path);
di.Attributes = FileAttributes.Directory | FileAttributes.Hidden;
}
从here。
CreateHiddenFolder(string name)
{
DirectoryInfo di = new DirectoryInfo(name);
di.Create();
di.Attributes |= FileAttributes.Hidden;
}
仅获取根文件夹路径的代码。
一样,如果我们有C:/测试/ C:/测试/ ABC C:/测试/ XYZ C:/ Test2的/ C:/ Test2的/ MNP
它将返回根文件夹路径即 C:/测试/ 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++;
}
重新标记,因为这不是对谷歌 – 2008-09-18 14:35:20