Подтвердить что ты не робот

Создание скрытых папок

Есть ли способ, с помощью которого я могу программно создавать (и, я предполагаю, доступ) скрытые папки на устройстве хранения данных изнутри С#?

4b9b3361

Ответ 1

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

Ответ 2

Да, вы можете. Создайте каталог как обычно, а затем просто установите атрибуты на нем. Например.

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

Ответ 3

CreateHiddenFolder(string name)  
{  
  DirectoryInfo di = new DirectoryInfo(name);  
  di.Create();  
  di.Attributes |= FileAttributes.Hidden;  
}  

Ответ 4

string path = @"c:\folders\newfolder"; // or whatever 
if (!System.IO.Directory.Exists(path)) 
{ 
    DirectoryInfo di = Directory.CreateDirectory(path); 
    di.Attributes = FileAttributes.Directory | FileAttributes.Hidden; 
}

Из здесь.

Ответ 5

Код, чтобы получить только путь корневых папок.

Например, если у нас есть C:/Test/ C:/Тест/А C:/Тест/хуг C:/Test2/ C:/Test2/МНП

Он вернет путь к корневым папкам, т.е. 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++;                    
            }