MSDN中SetAttributes例子拓展
2006-11-10 00:38
295 查看
MSDN例子:
示例
下面的示例通过将 Archive 和 Hidden 属性应用于文件,演示了 GetAttributes 和 SetAttributes 方法。
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);
}
}
}
拓展例子:可在保留其它属性情况下显示或隐藏文件
using System;
using System.IO;
using System.Text;
namespace setAttributes
{
/// <summary>
/// Class1 的摘要说明。
/// </summary>
class Class1
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main(string[] args)
{
//
// TODO: 在此处添加代码以启动应用程序
//
string path = @"c:/temp/test.txt";
if ( !File.Exists(path))
{
File.Create(path);
}
if ( (File.GetAttributes(path) & FileAttributes.Hidden) == FileAttributes.Hidden )
{
//show files
File.SetAttributes(path,(FileAttributes)(Convert.ToInt32(File.GetAttributes(path))-Convert.ToInt32(FileAttributes.Hidden)));
Console.WriteLine("The {0} file is no longer hidden.", path);
}
else
{
//hidden files
File.SetAttributes(path,File.GetAttributes(path) | FileAttributes.Hidden);
Console.WriteLine("The {0} file is hidden.",path);
}
}
}
}
心得:FileAttributes枚举属性可按int格式进行运算
示例
下面的示例通过将 Archive 和 Hidden 属性应用于文件,演示了 GetAttributes 和 SetAttributes 方法。
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);
}
}
}
拓展例子:可在保留其它属性情况下显示或隐藏文件
using System;
using System.IO;
using System.Text;
namespace setAttributes
{
/// <summary>
/// Class1 的摘要说明。
/// </summary>
class Class1
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main(string[] args)
{
//
// TODO: 在此处添加代码以启动应用程序
//
string path = @"c:/temp/test.txt";
if ( !File.Exists(path))
{
File.Create(path);
}
if ( (File.GetAttributes(path) & FileAttributes.Hidden) == FileAttributes.Hidden )
{
//show files
File.SetAttributes(path,(FileAttributes)(Convert.ToInt32(File.GetAttributes(path))-Convert.ToInt32(FileAttributes.Hidden)));
Console.WriteLine("The {0} file is no longer hidden.", path);
}
else
{
//hidden files
File.SetAttributes(path,File.GetAttributes(path) | FileAttributes.Hidden);
Console.WriteLine("The {0} file is hidden.",path);
}
}
}
}
心得:FileAttributes枚举属性可按int格式进行运算
相关文章推荐
- msdn的一个例子 移动就是这么简单..
- 体验了一下msdn2012,挺好用的,可以找到所有的函数,进行调用,还有例子。
- 微软MSDN:“Example: Creating a WMI Application”例子代码中的错误
- MSDN 条件变量使用例子
- MSDN上的异步socket 服务端例子
- 把MSDN中的例子从vc.net转到vc6下面的土办法
- 通过MSDN上的例子学习管道读写技术
- MSDN处理异常的例子
- VC++ MSDN中的 _beginthreadex与_endthreadex 的使用例子
- !!! C++/CLI中使用using namespace System::Windows::Forms;+MessageBox报错---最重要的是看MSDN 每个函数的使用例子
- java用两个例子充分阐述多态的可拓展性介绍
- msdn中的ginA例子中的WlxLoggedOutSAS
- 写给初学者:一个调试、利用msdn的经典例子
- MSDN中回调函数的讲解及其C#例子:用委托实现回调函数
- MSDN中SetWindowsHookEx的例子代码
- 委托和事件的一个例子解读From msdn of Microsoft
- java枚举(二):即对java枚举(一)中的例子进行拓展
- 一个调试、利用msdn的经典例子
- MSDN中回调函数的讲解及其C#例子:用委托实现回调函数
- 微软MSDN中ado的例子