Unit de teste de backup de arquivo no Delphi
unit UPrincipal;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
//function VerificaNumero(Valor : string) : boolean;
public
{ Public declarations }
end;
var
Form1: TForm1;
teste : Boolean;
implementation
{$R *.dfm}
procedure copiar();
var
SR: TSearchRec;
I: integer;
Origem, Destino: string;
begin
{ Copiar e substituir se existente
CopyFile(\'C:\\Arquivo\\Origem\',\'C:\\Arquivo\\Destino\',false);
Copiar e NÃO substituir se existente
CopyFile(\'C:\\Arquivo\\Origem\',\'C:\\Arquivo\\Destino\',true);
}
I := FindFirst('C:\Teste\P1\\banco.mdb', faAnyFile, SR);
//I := FindFirst('C:\Teste\P1\\*.*', faAnyFile, SR); Copia todos os arquivos
//ShowMessage(IntToStr(I));
while I = 0 do begin
if (SR.Attr and faDirectory) <> faDirectory then begin
Origem := 'C:\Teste\P1\\' + SR.Name;
Destino := 'C:\Teste\P2\\' + SR.Name;
if not CopyFile(PChar(Origem), PChar(Destino), false) then
ShowMessage('Erro ao copiar \' + Origem + ' para \' + Destino);
end;
ShowMessage('Arquivos copiados com sucesso!');
I := FindNext(SR);
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
texto : string;
begin
copiar;
texto := Edit1.Text;
ShowMessage(texto);
//VerificaNumero(texto);
end;
//função para retornar se a string é um numero inteiro ou não
function VerificaNumero(Valor : string) : boolean;
var
i : integer;
Begin
result := true;
try
i := strtoInt(valor);
except
result := false;
end;
end;
{
var
nome : string;
begin
nome := Edit1.Text;
if not DirectoryExists('C:\'+nome) then
ForceDirectories('C:\'+nome);
end;
}
end.