-
Notifications
You must be signed in to change notification settings - Fork 1
/
IsFileCorrect.pas
56 lines (56 loc) · 1.15 KB
/
IsFileCorrect.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
function IsFileCorrect(fileandpath: string): Boolean;
//
// Testa se o arquivo possui caracteres inválidos em seu nome
//
const
BADCHARS = '/\?"*:<>|';
var
i: integer;
dir,filename: string;
begin
if Length(FileAndPath) > 0 then
begin
for i := Length(fileandPath) downto 1 do
begin
if fileandPath[i] = '\' then
begin
break;
end;
end;
dir := Copy(FileAndPath, 1, i);
if Length(dir) > 0 then
begin
if (DirectoryExists(dir)) then
begin
FileName := Copy(FileAndPath, i+1, Length(FileAndPath));
end
else
begin
Result := False;
Exit;
end;
end
else
begin
FileName := FileAndPath;
end;
for i := Length(BADCHARS) downto 1 do
begin
if Pos(BADCHARS[i], filename) > 0 then
begin
Result := False;
exit;
end;
end;
if (Length(Filename) = 0) or (Length(FileName) > 256) then
begin
Result := False;
Exit;
end;
Result := True;
end
else
begin
Result := False;
end;
end;