Delphi 備份小工具

摘要:Delphi 備份小工具

單純個人工作上此使用

在程式更新之前把舊的dll先備份到本機D碟上

緊急情況可以使用。

 

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ComCtrls,ShellApi;
  
type
  TForm1 = class(TForm)
    Button1: TButton;
    Edit1: TEdit;
    CheckBox1: TCheckBox;
    CheckBox2: TCheckBox;
    Edit2: TEdit;
    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
         procedure WMDropFiles(var Msg: TWMDropFiles); message WM_DROPFILES;
     //宣告攔截檔案拖曳的 windows Mseeage
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var path, dir :string;

begin
    dir:= FormatDateTime('yyyymmdd',NOW);
    if ((CheckBox1.Checked=true) and (edit1.Text <>'')) then
    begin
    if not DirectoryExists('D:\NEW_DLL') then
        CreateDir('D:\NEW_DLL');
        path := 'D:\NEW_DLL\';
        if not DirectoryExists(path   +dir ) then
       CreateDir(path + dir);
       //ExtractFileName(FileName);  //去除檔案的路徑
       //FileName := ChangeFileExt(ExtractFileName(FileName),'');  // 檔名
       CopyFile(PChar(edit1.Text), PChar(path + dir+ '\'+ExtractFileName(edit1.Text) ), True)
       //False為覆蓋參數﹐當有同名檔案存在時﹐False參數為覆蓋處理﹐True參數為中止處理﹐即不做复制
    end;

    if ((CheckBox2.Checked=true) and (edit2.Text <>'')) then
    begin
     if not DirectoryExists('D:\OLD_DLL') then
        CreateDir('D:\OLD_DLL');
        path := 'D:\OLD_DLL\';
       if not DirectoryExists(path   +dir ) then
       CreateDir(path + dir);
       CopyFile(PChar(edit2.Text), PChar(path + dir+ '\'+ExtractFileName(edit2.Text) ), False)
    end;

end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  DragAcceptFiles(Handle, True); // 設定 Form 可以接受拖曳
end;
procedure TForm1.WMDropFiles(var Msg: TWMDropFiles);
Var
  i,FileCount:integer;
  FileName:array[0..255] of char;
  FileNameList:TStringList;
begin
  FileNameList:=TStringList.Create;
  FileCount := DragQueryFile(Msg.Drop,$FFFFFFFF,nil,0); //檔案的總數
  for i := 0 to (FileCount - 1) do
  begin
    DragQueryFile(Msg.Drop,i,@FileName,sizeof(FileName)); //取得檔案名稱
    FileNameList.Add(FileName); //存入 FileNameList
    if(edit1.text ='') then
    edit1.Text    :=FileName
    else
    edit2.Text    :=FileName;
  end;
  {你想怎麼處理}
  FileNameList.Free;
end;
end.

 

參考

 http://delphi.ktop.com.tw/board.php?cid=30&fid=71&tid=21922

http://blog.xuite.net/dian.hk1211/jvc/6936785

更新備份器.zip

 

 

 

 

大家一起加入blogads 賺零用錢!!