C#改变文件属性

 1 string path   =   @"c:\temp\MyTest.txt";   
2 // check file.
3 if(!File.Exists(path))
4 {
5 File.Create(path);
6 }
7 if((File.GetAttributes(path)&FileAttributes.Hidden)==FileAttributes.Hidden)
8 {
9 //Show the file.
10 File.SetAttributes(path,FileAttributes.Archive);
11 Console.WriteLine("The {0} file is no longer hidden.", path);
12 }
13 else
14 {
15 //Hide the file.
16 File.SetAttributes(path, File.GetAttributes(path)|FileAttributes.Hidden);
17 Console.WriteLine("The {0} file is now hidden.", path);
18 }

 

你可能感兴趣的:(C#)