我是否可以在C#中以编程方式创建(并访问)存储设备上的隐藏文件夹?
我是否可以在C#中以编程方式创建(并访问)存储设备上的隐藏文件夹?
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;
}
可以的。像平常一样创建目录,然后只需设置其属性即可。例如:
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))
。 - schoetbiCreateHiddenFolder(string name)
{
DirectoryInfo di = new DirectoryInfo(name);
di.Create();
di.Attributes |= 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;
}
From here.
获取仅根文件夹路径的代码。
例如,如果我们有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++;
}