C#操作文件
本人在C:\內有一文件A.zip,想問問用C#如何操作它成一個隱藏文件??意思是指按下一Button後該文件會設屬性是隱藏 ????? --------------------编程问答-------------------- File Class
Namespace: System.IO
File.SetAttributes Method
public static void SetAttributes (
string path,
FileAttributes fileAttributes
)
using System;
using System.IO;
using System.Text;
class Test
{
public static void Main()
{
string path = @"c:\temp\MyTest.txt";
// Create the file if it does not exist.
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);
}
}
}
you can find all above code in MSDN
--------------------编程问答-------------------- //using System.IO;
File.SetAttributes(@"C:\A.zip",FileAttributes.Hidden);
补充:.NET技术 , C#