delphi 按图像的创建日期改名  
官方Delphi 学习QQ群: 682628230(三千人)
频道

delphi 按图像的创建日期改名


unit Unit1;


interface


uses

  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,

  Dialogs, FileCtrl, StdCtrls, ComCtrls;


type

  TForm1 = class(TForm)

    OpenDialog1: TOpenDialog;

    DirectoryListBox1: TDirectoryListBox;

    DriveComboBox1: TDriveComboBox;

    Button1: TButton;

    FileListBox1: TFileListBox;

    ProgressBar1: TProgressBar;

    procedure Button1Click(Sender: TObject);

  private

    { Private declarations }

  public

    { Public declarations }

  end;


var

  Form1: TForm1;


implementation


{$R *.dfm}

function CovFileDate(Fd: _FileTime): TDateTime;

{ 转换文件的时间格式 }

var

  Tct: _SystemTime;

  Temp: _FileTime;

begin

  FileTimeToLocalFileTime(Fd, Temp);

  FileTimeToSystemTime(Temp, Tct);

  CovFileDate := SystemTimeToDateTime(Tct);

end;


function GetFileTime(const Tf: string): string;

{ 获取文件时间,Tf表示目标文件路径和名称 }

const

  Model = 'yyyyMMdd-HHmmss'; { 设定时间格式 }

var

  Tp: TSearchRec; { 申明Tp为一个查找记录 }

  T1, T2, T3: string;

begin

  FindFirst(Tf, faAnyFile, Tp); { 查找目标文件 }

  //T1 := FormatDateTime(Model, CovFileDate(Tp.FindData.ftCreationTime));

{ 返回文件的创建时间 }

  T2 := FormatDateTime(Model, CovFileDate(Tp.FindData.ftLastWriteTime));

{ 返回文件的修改时间 }

  //T3 := FormatDateTime(Model, Now);

{ 返回文件的当前访问时间 }

  FindClose(Tp);

  Result := t2;

end;


procedure TForm1.Button1Click(Sender: TObject);

var

  i: integer;

  fullfile, newfile, fileext: string;

begin

  ProgressBar1.Max := FileListBox1.Items.Count;

  ProgressBar1.Min := 0;

  ProgressBar1.Position := 0;

  for  i := 0 to FileListBox1.Items.Count - 1 do

  begin

    fileext := ExtractFileExt(FileListBox1.Items[i]);

    if (Length(fileext) < 2) then Continue;

    RenameFile(FileListBox1.Directory + '\' + FileListBox1.Items[i], FileListBox1.Directory + '\' + GetFileTime(FileListBox1.Directory + '\' + FileListBox1.Items[i]) + fileext);

    Application.ProcessMessages;

  end;

  FileListBox1.Update;

end;


end.



推荐分享
图文皆来源于网络,内容仅做公益性分享,版权归原作者所有,如有侵权请告知删除!
 

Copyright © 2014 DelphiW.com 开发 源码 文档 技巧 All Rights Reserved
晋ICP备14006235号-8 晋公网安备 14108102000087号

执行时间: 0.037014961242676 seconds