以编程方式隐藏和阻止删除文件夹 [英] Hide and Prevent Delete Folder Programmatically
本文介绍了以编程方式隐藏和阻止删除文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好,
我想以语法方式隐藏文件夹,以便如果我们从文件夹选项"中选中显示隐藏的文件和文件夹",则该文件夹将不会成为查看事件.
我也想添加更多属性,以便我们不能删除此文件夹
我有下面的代码.我想设置隐藏并防止删除"Folder2",但无法使用文件夹"选项隐藏-
请帮忙!!!
Hello There,
I want to Hide Folder Pro-grammatically so that folder can''t be view event if we Check - "Show Hidden File and Folder" from "Folder Options".
Also I want to add more attribute so that we can''t Delete this Folder
I have below Code. I want to set hide and prevent deletion for "Folder2", but not able hide using Folder options --
Please help!!!
DirectoryInfo dirinfo = new DirectoryInfo("C:\Test Folder\Folder2");
dirinfo.Attributes = FileAttributes.Hidden;
dirinfo.Attributes = FileAttributes.System;
推荐答案
它将像这样工作:
It will works like this:
string dirPath = @"C:\Test Folder\Folder2";
if (!Directory.Exists(dirPath))
{
DirectoryInfo di = Directory.CreateDirectory(dirPath);
di.Attributes = FileAttributes.Directory | FileAttributes.Hidden | FileAttributes.System;
}
If Directory.Exists("D:\Folder") Then
Dim divinfo As New DirectoryInfo("D:\Folder")
divinfo.Attributes = FileAttributes.Hidden
End If
这篇关于以编程方式隐藏和阻止删除文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文