您的位置:首页 > 编程语言 > C#

C#文件基本操作2-获取文件基本信息

2013-06-11 10:15 316 查看
原来的样例是用MESSAGEBOX来输出,我改成用RICHTEXT来输出。好看点哈。

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;

namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
textBox1.Text = openFileDialog1.FileName;
FileInfo finfo = new FileInfo(textBox1.Text);
string strCTime, strLATime, strLWTime, strName, strFName, strDName, strISRead, lgLength;
string strContent;
strCTime = finfo.CreationTime.ToShortDateString();
strLATime = finfo.LastAccessTime.ToShortDateString();
strLWTime = finfo.LastWriteTime.ToShortDateString();
strName = finfo.Name;
strFName = finfo.FullName;
strDName = finfo.DirectoryName;
strISRead = finfo.IsReadOnly.ToString();
lgLength = finfo.Length.ToString();

strContent = "文件信息:\n创建时间: "+ strCTime +
"\n上次访问时间:" + strLATime +
"\n上次写入时间:" + strLWTime +
"\n文件名称:" + strName +
"\n完整目录:" + strFName +
"\n完整路径:" + strDName +
"\n是否只读:" + strISRead +
"\n文件长度:" + lgLength;
richTextBox1.Text = strContent;
}
}
}
}


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐