using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace ConAppFile
{
class Program
{ //file类,文件删除、创建、重名、复制设置文件属性。
static void Main(string[] args)
{
string filePath = @"c:\temp\textfile.txt";
string fileCopyPath = @"c:\temp\textfile_copy.txt";
string newFileName = @"c:\temp\textfile_newCopy.txt";
try
{ //判断文件已经存在
if (File.Exists(filePath))
{
//删除这个文件
File.Delete(filePath);
}
//再次创建文件
FileStream fs = File.Create(filePath);
fs.Close();
//复制文件
File.Copy(filePath, fileCopyPath);
//更改文件名字
File.Move(fileCopyPath,newFileName);
//显示创建时间
Console.WriteLine(File.GetCreationTime(newFileName));
//....make the file read_only and hidden...
File.SetAttributes(newFileName,FileAttributes.ReadOnly);
File.SetAttributes(newFileName, FileAttributes.Hidden);
}
catch (IOException ex)
{
Console.WriteLine(ex.Message);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
Console.ReadLine();
}
}
}
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END
暂无评论内容