-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmArquivo.pas
113 lines (89 loc) · 2.25 KB
/
mArquivo.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
unit mArquivo;
interface
uses
Classes, SysUtils, Windows;
type
TmArquivo = class
public
class procedure Adicionar(AArquivo, AConteudo : String);
class procedure Gravar(AArquivo, AConteudo : String);
class function Ler(AArquivo : String) : String;
class procedure Excluir(AArquivo : Array Of String);
class procedure Copiar(AOrigem, ADestino : String);
class procedure Mover(AOrigem, ADestino : String);
end;
implementation
{ TmArquivo }
class procedure TmArquivo.Adicionar(AArquivo, AConteudo: String);
var
vFile : TextFile;
begin
AssignFile(vFile, AArquivo);
try
if FileExists(AArquivo) then
Append(vFile)
else
Rewrite(vFile);
WriteLn(vFile, AConteudo);
finally
CloseFile(vFile)
end;
end;
class procedure TmArquivo.Excluir(AArquivo: array of String);
var
I : Integer;
begin
for I := 0 to High(AArquivo) do
if FileExists(AArquivo[I]) then
DeleteFile(PAnsiChar(AArquivo[I]));
end;
class procedure TmArquivo.Gravar(AArquivo, AConteudo: String);
var
vDir : String;
vBuffer : Byte;
vFile : File;
I : Integer;
begin
if FileExists(AArquivo) then
DeleteFile(PChar(AArquivo));
vDir := ExtractFileDir(AArquivo);
ForceDirectories(vDir);
AssignFile(vFile, AArquivo);
ReWrite(vFile, 1);
for I:=1 to Length(AConteudo) do begin
vBuffer := Ord(AConteudo[I]);
BlockWrite(vFile, vBuffer, 1);
end;
CloseFile(vFile);
end;
class function TmArquivo.Ler(AArquivo: String): String;
var
readcnt : Integer;
vFile : File;
vByte : Byte;
begin
Result := '';
if not FileExists(AArquivo) then
Exit;
AssignFile(vFile, AArquivo);
FileMode := 0; // modo somente leitura
Reset(vFile, 1);
repeat
BlockRead(vFile, vByte, 1, readcnt);
if (readcnt <> 0) then Result := Result + Chr(vByte);
until (readcnt = 0);
CloseFile(vFile);
end;
class procedure TmArquivo.Copiar(AOrigem, ADestino: String);
begin
if (AOrigem <> '') and (ADestino <> '') then
if FileExists(AOrigem) then
CopyFile(PAnsiChar(AOrigem), PAnsiChar(ADestino), False);
end;
class procedure TmArquivo.Mover(AOrigem, ADestino: String);
begin
if (AOrigem <> '') and (ADestino <> '') then
if FileExists(AOrigem) then
MoveFile(PAnsiChar(AOrigem), PAnsiChar(ADestino));
end;
end.