zoukankan      html  css  js  c++  java
  • 获取设置目录创建、访问、修改时间

    使用函数:

      System.IOUtils.TDirectory.GetCreationTime

      System.IOUtils.TDirectory.GetLastAccessTime

      System.IOUtils.TDirectory.GetLastWriteTime

      System.IOUtils.TDirectory.SetCreationTime

      System.IOUtils.TDirectory.SetLastAccessTime

      System.IOUtils.TDirectory.SetLastWriteTime

    代码:

      

    unit Unit1;
    
    interface
    
    uses
      Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
      Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.FileCtrl, System.IOUtils;
    
    type
      TForm1 = class(TForm)
        Label1: TLabel;
        Label2: TLabel;
        Label3: TLabel;
        Edit_CreateTime: TEdit;
        Edit_AccessTime: TEdit;
        Edit_WriteTime: TEdit;
        Button1: TButton;
        Button_GetTime: TButton;
        Button_SetTime: TButton;
        procedure Button1Click(Sender: TObject);
        procedure Button_GetTimeClick(Sender: TObject);
        procedure Button_SetTimeClick(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;
    
    var
      Form1: TForm1;
    
    implementation
    
    {$R *.dfm}
    var
        sDir: string;
    procedure TForm1.Button1Click(Sender: TObject);
    begin
        if not SelectDirectory('', 'H:	mp', sDir)then Exit;
        Text := sDir;
    end;
    
    procedure TForm1.Button_GetTimeClick(Sender: TObject);  //GetTime
    begin
        try
            Edit_CreateTime.Text := DateTimeToStr(TDirectory.GetCreationTime(sDir));
            Edit_AccessTime.Text := DateTimeToStr(TDirectory.GetLastAccessTime(sDir));
            Edit_WriteTime.Text := DateTimeToStr(TDirectory.GetLastWriteTime(sDir));
        except
            on e: Exception do
            begin
                MessageDlg(e.ClassName + ' : ' + e.Message, mtError, [mbok], 0);
                Exit;
            end;
        end;
    end;
    
    procedure TForm1.Button_SetTimeClick(Sender: TObject); //SetTime
    begin
        try
            TDirectory.SetCreationTime(sDir, StrToDateTime(Edit_CreateTime.Text));
            TDirectory.SetLastAccessTime(sDir, StrToDateTime(Edit_AccessTime.Text));
            TDirectory.SetLastWriteTime(sDir, StrToDateTime(Edit_WriteTime.Text));
            ShowMessage('设置完成!');
        except
            on e: Exception do
            begin
                MessageDlg(e.ClassName + ' : ' + e.Message, mtError, [mbok], 0);
                Exit;
            end;
        end;
    end;
    
    end.

     

  • 相关阅读:
    DS博客作业02--线性表
    DS博客作业01--日期抽象数据类型设计与实现
    C语言博客作业06--结构体&文件
    C语言博客作业05--指针
    C语言博客作业04--数组
    DS博客作业8——课程总结
    DS博客作业07——查找
    DS博客作业06--图
    DS博客作业——树
    DS博客作业03--栈和队列
  • 原文地址:https://www.cnblogs.com/cause/p/3501804.html
Copyright © 2011-2022 走看看