首页 > Windows开发 > 详细

c# 文件属性读取操作及文件之间操作

时间:2016-11-18 22:48:53      阅读:283      评论:0      收藏:0      [点我收藏+]

c# 获取文件最后修改日期代码
FileInfo f = new FileInfo(@"c:\1.txt");
Console.WriteLine(f.LastWriteTime.ToString());
c# 获取文件最后访问时间代码
FileInfo f = new FileInfo(@"c:\1.txt");
Console.WriteLine(f.LastAccessTime.ToString());//最后访问
c# 获取文件创建时间代码
FileInfo f = new FileInfo(@"c:\1.txt");
Console.WriteLine(f.CreationTime.ToString());
c# 获取文件大小代码
FileInfo f = new FileInfo(@"c:\1.txt");
Console.WriteLine(f.Length.ToString());
c# 获取文件文件属性代码
FileInfo f = new FileInfo(@"c:\1.txt");
Console.WriteLine(f.Attributes);

C#文件路径

 

 FileInfo f = new FileInfo(@"c:\1.txt");
Console.WriteLine(f.DirectoryName);
 
 C#追加文件
    StreamWriter sw = File.AppendText(Server.MapPath(".")+"\\myText.txt");
    sw.WriteLine("追逐理想");
    sw.WriteLine("kzlll");
    sw.WriteLine(".NET笔记");
    sw.Flush();
    sw.Close();
C#拷贝文件
    string OrignFile,NewFile;
    OrignFile = Server.MapPath(".")+"\\myText.txt";
    NewFile = Server.MapPath(".")+"\\myTextCopy.txt";
    File.Copy(OrignFile,NewFile,true);
C#删除文件
    string delFile = Server.MapPath(".")+"\\myTextCopy.txt";
    File.Delete(delFile);
C#移动文件
    string OrignFile,NewFile;
    OrignFile = Server.MapPath(".")+"\\myText.txt";
    NewFile = Server.MapPath(".")+"\\myTextCopy.txt";
    File.Move(OrignFile,NewFile);
 
 
讲文件从一个目录复制到另一个目录
 FileInfo fi = new FileInfo(path1);
fi.CopyTo(path2, true);
path1源文件路径,path2目标文件路径。
阅读(2423)评论(0)

c# 文件属性读取操作及文件之间操作

原文:http://www.cnblogs.com/ajimide/p/6078572.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!