• TDirectory.GetCreationTime、TDirectory.SetCreationTime获取和设置文件夹创建时间


    使用函数:

      System.IOUtils.TDirectory.GetCreationTime//获取创建时间

      System.IOUtils.TDirectory.SetCreationTime//设置创建时间

      注:UTC结尾的返回 <Coordinated Universal Time即协调世界时>。

    示例:

    代码

    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)
        Button_GetCreateTime: TButton;
        Button_SetCreateTime: TButton;
        Edit_Time: TEdit;
        Button_ChooseFolder: TButton;
        Label_Path: TLabel;
        Memo1: TMemo;
        procedure Button_ChooseFolderClick(Sender: TObject);
        procedure Button_GetCreateTimeClick(Sender: TObject);
        procedure Button_SetCreateTimeClick(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;
    
    var
      Form1: TForm1;
    
    implementation
    
    {$R *.dfm}
    var
        sDir: string;
    procedure TForm1.Button_ChooseFolderClick(Sender: TObject);
    begin
        if not SelectDirectory('请选择一个文件夹', 'H:', sDir) then  Exit;
        Label_Path.Caption := sDir;
        Button_SetCreateTime.Enabled := True;
        Button_GetCreateTime.Enabled := True;
    end;
    
    procedure TForm1.Button_GetCreateTimeClick(Sender: TObject);
    var
        CTime: TDateTime;
    begin
        //
        try
            CTime := TDirectory.GetCreationTime(Label_Path.Caption);
            Edit_Time.Text := DateTimeToStr(CTime);
    
        except
            on e: Exception do
            begin
                MessageDlg('获取失败!' + e.Message, mtError, [mbok], 0);
                Exit;
            end;
        end;
    end;
    
    procedure TForm1.Button_SetCreateTimeClick(Sender: TObject);
    begin
        try
            TDirectory.SetCreationTime(Label_Path.Caption, StrToDateTime(Edit_Time.Text));
        except
            on e1: Exception do
            begin
                MessageDlg('设置失败!' + e1.Message, mtError, [mbok], 0);
                Exit;
            end;
        end;
    end;
    
    end.
  • 相关阅读:
    [JS]格式化Date和分析格式化Date字符串的JS代码
    发布一个实用美观的Vista Sidebar Gadget (代表博客园参赛)
    2月8号N706从深圳回湖南,有没有同行的,呵呵
    LiveWriter测试
    自动内容滚动条[WinForm控件]
    关于Ajax的一揽子工程(1)
    “做事先做人”实战
    成熟度即流程
    金秋游故宫
    html块状元素、内联元素
  • 原文地址:https://www.cnblogs.com/cause/p/3496474.html
Copyright © 2020-2023  润新知