首页 新闻 会员 周边

获取文件夹和文件是否隐藏的属性

0
[已解决问题] 解决于 2008-08-20 08:01
如题,我想判断一个文件或文件夹是否隐藏,但弄了很久也没调试出来。大家帮帮忙。
少之的主页 少之 | 菜鸟二级 | 园豆:205
提问于:2008-08-19 16:09
< >
分享
最佳答案
0
using System; using System.IO; using System.Text; class Test { public static void Main() { string path = @"c:\temp\MyTest.txt"; // Delete the file if it exists. if (!File.Exists(path)) { File.Create(path); } if ((File.GetAttributes(path) & FileAttributes.Hidden) == FileAttributes.Hidden) { // Show the file. File.SetAttributes(path, FileAttributes.Archive); Console.WriteLine("The {0} file is no longer hidden.", path); } else { // Hide the file. File.SetAttributes(path, File.GetAttributes(path) | FileAttributes.Hidden); Console.WriteLine("The {0} file is now hidden.", path); } } }
玉开 | 大侠五级 |园豆:8822 | 2008-08-19 16:59
其他回答(1)
0
FileAttributes attr = File.GetAttributes(filePath); if ((attr & FileAttributes.Hidden) == FileAttributes.Hidden) { //... }
Gray Zhang | 园豆:17610 (专家六级) | 2008-08-19 17:03
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册