interface
uses Windows, Messages, SysUtils, Classes;
const
False_File_Chars: array[0..8] of char =
('\', '/', ':', '*', '?', '"', '<', '>', '|');
function GermanTime: string;
function GermanDate: string;
function IsFileNameExt(FileName, FileExt: string): Boolean;
function PosFileNameExt(FileName: string): Integer;
function CutFileNameExt(FileName: string): string;
function ChangeFileNameExt(FileName, NewExt: string):
string;
function AddBackSlash(Path: string): string;
function CutBackSlash(Path: string): string;
function IsCorrectFileName(FileName: string): Boolean;
function MakeCorrectFileName(FileName: string): string;
function GetSizeStr(Size: LongInt): string;
implementation
function GermanTime: string;
var t: string;
begin
t:=(TimeToStr(Time));
result:=Copy(t, 1, 2)+' Uhr '+Copy(t, 4, 2)+' '+Copy(t, 7, 2)+' s';
end;
function GermanDate: string;
var d: string;
begin
d:=FormatDateTime('dd mm yyyy', StrToDateTime(DateToStr(Date)));
result:=Copy(d, 1, 2)+'. '+LongMonthNames[strtoint(Copy(d, 4, 2))]+'
'+Copy(d, 7, 4);
end;
function IsFileNameExt(FileName, FileExt: string): Boolean;
begin
result:=(CompareText(ExtractFileExt(FileName), FileExt)=0);
end;
function PosFileNameExt(FileName: string): Integer;
begin
result:=Pos(ExtractFileExt(FileName), FileName);
end;
function CutFileNameExt(FileName: string): string;
begin
result:=FileName;
Delete(result, Pos(ExtractFileExt(result), result), Length(ExtractFileExt(result)));
end;
function ChangeFileNameExt(FileName, NewExt: string):
string;
begin
result:=CutFileNameExt(FileName) + NewExt;
end;
function AddBackSlash(Path: string): string;
begin
result:=Path;
if Copy(Path, Length(Path), 1)<>'\' then result:=Path+'\';
end;
function CutBackSlash(Path: string): string;
begin
result:=Path;
if (Copy(Path, Length(Path), 1)='\') and (Copy(Path, Length(Path)-1,
1)<>':') then
result:=Copy(Path, 1, Length(Path)-1);
end;
function IsCorrectFileName(FileName: string): Boolean;
var cv: Integer;
begin
result:=True;
for cv:=0 to 8 do
if Pos(False_File_Chars[cv], FileName)>0 then
result:=False;
end;
function MakeCorrectFileName(FileName: string): string;
var cv: Integer;
begin
result:=FileName;
for cv:=0 to 8 do
while Pos(False_File_Chars[cv], result)>0 do
Delete(result, Pos(False_File_Chars[cv],
result), 1);
end;
function GetSizeStr(Size: LongInt): string;
var cv: Integer;
begin
if Size>=1048576 then
begin
cv:=Pos(',', FloatToStr(Size/1048576));
if cv=0 then
result:=FloatToStr(Size/1048576)+' MB'
else
result:=Copy(FloatToStr(Size/1048576),
1, cv+2)+' MB';
end;
if (Size<1048576) and (Size>=1024) then
begin
cv:=Pos(',', FloatToStr(Size/1024));
if cv=0 then
result:=FloatToStr(Size/1024)+' KB'
else
result:=Copy(FloatToStr(Size/1024),
1, cv-1)+' KB';
end;
if Size<1024 then result:=inttostr(Size)+' Bytes';
end;