C#檔案建立、修改、訪問時間修改

來源:互聯網
上載者:User

標籤:win   http   lte   last   檔案建立   ace   .com   oid   har   

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#檔案建立、修改、訪問時間修改

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.