创建隐藏文件夹
时间:2020-03-06 14:21:11 来源:igfitidea点击:
有什么方法可以从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;
}
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;
}

