forked from sergworks/tforge
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathCopyFiles.dpr
executable file
·107 lines (95 loc) · 2.66 KB
/
CopyFiles.dpr
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
program CopyFiles;
{$APPTYPE CONSOLE}
uses
SysUtils, Windows;
const
SourceDir = 'c:\projects\tforge\tforge';
TargetDir = 'c:\projects\tforge\release';
type
TIgnoreList = array of string;
var
DirIgnoreList: TIgnoreList;
ExtIgnoreList: TIgnoreList;
function ValidName(const Name: string; const List: TIgnoreList): Boolean;
var
CurrName, UpperName: string;
begin
UpperName:= UpperCase(Name);
for CurrName in List do begin
if UpperCase(CurrName) = UpperName then begin
Result:= False;
Exit;
end;
end;
Result:= True;
end;
procedure ClearDir(const DirName: string; Level: Integer = 0);
var
Path: string;
F: TSearchRec;
begin
Path:= DirName + '\*.*';
if SysUtils.FindFirst(Path, faAnyFile, F) = 0 then begin
try
repeat
if (F.Attr and faDirectory <> 0) then begin
if (F.Name <> '.') and (F.Name <> '..') then begin
ClearDir(DirName + '\' + F.Name, Level + 1);
end;
end
else
Windows.DeleteFile(PChar(DirName + '\' + F.Name));
until SysUtils.FindNext(F) <> 0;
finally
SysUtils.FindClose(F);
end;
end;
if Level > 0 then RemoveDir(DirName);
end;
procedure CopyDir(const FromName, ToName: string);
var
Path: string;
FromPath, ToPath: string;
F: TSearchRec;
begin
Path:= FromName + '\*.*';
if SysUtils.FindFirst(Path, faAnyFile, F) = 0 then begin
try
repeat
FromPath:= FromName + '\' + F.Name;
ToPath:= ToName + '\' + F.Name;
if (F.Attr and faDirectory <> 0) then begin
if (F.Name <> '.') and (F.Name <> '..') then begin
if ValidName(F.Name, DirIgnoreList) then begin
ForceDirectories(ToPath);
CopyDir(FromPath, ToPath);
end;
end;
end
else begin
if ValidName(ExtractFileExt(F.Name), ExtIgnoreList) then begin
if not CopyFile(PChar(FromPath), PChar(ToPath), True)
then raise Exception.Create('Copy Failed !');
end;
end;
until SysUtils.FindNext(F) <> 0;
finally
SysUtils.FindClose(F);
end;
end;
end;
begin
try
DirIgnoreList:= TIgnoreList.Create('Utils', 'Ports', 'Misc',
'backup', '__history', '.hg', 'Debug', 'Release', 'lib');
ExtIgnoreList:= TIgnoreList.Create('.exe', '.dcu', '.hgignore', '.md',
'.identcache', '.local', '.lps', '.bak', '.aes', '.rc4');
ClearDir(TargetDir);
CopyDir(SourceDir, TargetDir);
except
on E: Exception do begin
Writeln(E.ClassName, ': ', E.Message);
Readln;
end;
end;
end.