C#文件创建、修改、访问时间修改
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing; using System.Text; using System.Windows.Forms;
using System.IO; namespace 修改文件创建日期或修改日期
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
string path = "";
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Title = "请选择要打开的文件";
ofd.Multiselect = false;
//ofd.InitialDirectory = @"C:\Uss\shaofeng\Desktop";
ofd.Filter = "文本文件|*.txt|所有文件|*.*";
ofd.ShowDialog();
path = ofd.FileName;
if (path=="")
{
return;
}
textBox1.Text = Path.GetFileName( path); FileInfo file = new FileInfo(path);
textBox2.Text = "创建时间:" + file.CreationTime.ToString() + "\r\n修改时间:" + file.LastWriteTime.ToString() + "\r\n访问时间:" + file.LastAccessTime.ToString(); } private void button2_Click(object sender, EventArgs e)
{
string strCuang = tboCuang.Text; string strXou = tboXou.Text; string strFw = tboFw.Text;
if (path=="")
{
return;
}
FileInfo file = new FileInfo(path);
try
{
int[] cj = strToNumTime(strCuang);
int[] xg = strToNumTime(strXou);
int[] fw = strToNumTime(strFw); file.CreationTime = new DateTime(cj[0], cj[1], cj[2], cj[3], cj[4], cj[5]);
file.LastWriteTime = new DateTime(xg[0], xg[1], xg[2], xg[3], xg[4], xg[5]);
file.LastAccessTime = new DateTime(fw[0], fw[1], fw[2], fw[3], fw[4], fw[5]); }
catch
{ }
finally
{
textBox3.Text = "创建时间:" + file.CreationTime.ToString() + "\r\n修改时间:" + file.LastWriteTime.ToString() + "\r\n访问时间:" + file.LastAccessTime.ToString();
} } private static int[] strToNumTime(string str)
{
string[] cjTime = str.Split(new char[] { ' ', '/', ':' }, StringSplitOptions.RemoveEmptyEntries);
int[] cj = new int[cjTime.Length];
for (int i = 0; i < cjTime.Length; i++)
{
cj[i] = Convert.ToInt32(cjTime[i]);
} return cj;
}
}
}

C#文件创建、修改、访问时间修改的更多相关文章
- VC++ 实现修改文件创建、访问、修改时间属性(转载)
转载:http://sunnysab.blog.163.com/blog/static/18037500920134221295425/ struct _FILETIME { //结构体定义 DWOR ...
- 通过反射 修改访问和修改属性的值 Day25
package com.sxt.field; /* * 通过反射拿到属性值 * 修改public属性值 * 修改private属性值 * 缺点:可读性差:代码复杂 * 优点:灵活:可以访问修改priv ...
- python 修改文件的创建时间、修改时间、访问时间
目录 python 修改文件创建.修改.访问时间 方案一 方案二(无法修改文件创建时间) python 修改文件创建.修改.访问时间 突如其来想知道一下 python 如何修改文件的属性(创建.修改. ...
- Linux下文件的三种时间标记:访问时间、修改时间、状态改动时间 (转载)
在windows下,一个文件有:创建时间.修改时间.访问时间. 而在Linux下,一个文件也有三种时间,分别是:访问时间.修改时间.状态改动时间. 两者有此不同,在Linux下没有创建时间的概念,也就 ...
- Linux学习笔记:touch新建文件、修改访问、改动时间
touch用于创建新的空文件或者修改已有文件的时间戳. 语法:touch file.txt 如果file存在,使用touch指令可更改这个文件或目录的日期时间,包括存取时间和更改时间. 如果file不 ...
- Linux查看和修改文件时间
参考http://www.361way.com/chang-file-time/1632.html 一:查看时间 1:查看文件的具体时间信息 File: `probn' Size: Blocks: I ...
- PHP获得文件创建、修改、访问时间 filectime() filemtime() fileatime()
转载博客 零度_PHP的博客 http://blog.sina.com.cn/s/blog_8edc37a801016hk1.html PHP获得文件创建.修改.访问时间 PHP filectim ...
- 在Linux中,没有文件创建时间的概念。只有文件的访问时间、修改时间、状态改变时间
在Linux中,没有文件创建时间的概念.只有文件的访问时间.修改时间.状态改变时间.也就是说不能知道文件的创建时间.但如果文件创建后就没有修改过,修改时间=创建时间:如果文件创建后,状态就没有改变过, ...
- Web 在线文件管理器学习笔记与总结(2)显示文件列表(名称,类型,大小,可读,可写,可执行,创建时间,修改时间,访问时间)
主要函数: filetype() 判断文件类型 filesize() 得到文件大小(字节) is_readable() 判断文件是否可读 is_writeable() 判断文件是否可写 is_exec ...
随机推荐
- 解决:IntelliJ IDEA 编译错误,提示 Compilation failed: internal java compiler error
原因可能是项目指定的JDK与当前环境JDK不符合,解决办法:File->Setting->Compiler->Java Compiler, 在相应的module中选择合适的JDK版本 ...
- Html5特性及简介
- c#中按键小技巧
以后会补充其他的内容
- 【003:jsoncpp的简单使用】
#include <json/json.h> #include <iostream> #include <string> using namespace std; ...
- Spring Mvc + Mybatis + sqlserver maven
mybatis config datasource: <!-- 配置数据源 使用的是Druid数据源 --> <bean name="dataSource" c ...
- zw.delphi不同版本程序运行速度测试
{ zw.delphi不同版本程序运行速度测试 delphi无论是开发,编译,还是运行,速度方面向来不差,笔者很少进行这种微粒度的优化,调试. 最近,因为项目需要,发现:同一个函数模块,差不多同样的代 ...
- DNS-2
ipconfig 用法: ipconfig [/allcompartments] [/? | /all | /renew [adapter] | /release [adapter] | /renew ...
- angularJS中directive与directive 之间的通信
上一篇讲了directive与controller之间的通信:但是我们directive与directive之间的通信呢? 当我们两个directive嵌套使用的时候怎么保证子directive不会被 ...
- Edittext默认无焦点
开发中,发现第一次进入页面时光标就会出现在页面的第一个edittext中,解决思路是: 在edittext的父布局中加入两行代码夺取焦点 <com.zhy.autolayout.AutoLine ...
- Tomcat去除项目名称和端口号,直接使用ip地址访问项目的方法
网站开发过程中,一般的工程访问路径是 http://112.74.51.37/projectName如何设置成http://112.74.51.37/ 解决方法: 首先,进入tomcat的安装目录下的 ...