Added examples 20-37

This commit is contained in:
michael 1999-05-13 21:49:26 +00:00
parent fd074a2629
commit 6be128f599
21 changed files with 634 additions and 21 deletions

View File

@ -32,7 +32,10 @@ endif
.PHONY: all tex clean
OBJECTS=ex1 ex2 ex3 ex4 ex5 ex6 ex7 ex8 ex9 ex10 ex11 ex12
OBJECTS=ex1 ex2 ex3 ex4 ex5 ex6 ex7 ex8 ex9 ex10 ex11 ex12\
ex13 ex14 ex15 ex16 ex17 ex18 ex19 ex20 ex21 ex22 ex23 ex24\
ex25 ex26 ex27 ex28 ex29 ex30 ex31 ex32 ex33 ex34 ex35 ex36\
ex37
TEXOBJECTS=$(addsuffix .tex, $(OBJECTS))

View File

@ -5,7 +5,6 @@ ex2.pp contains an example of the DateTimeToFileDate function.
ex3.pp contains an example of the DateTimeToStr function.
ex4.pp contains an example of the DateTimeToString function.
ex5.pp contains an example of the DateTimeToSystemTime function.
ex6.pp contains an example of the DateTimeToTimeStamp function.
ex7.pp contains an example of the DateToStr function.
exex8.pp contains an example of the DayOfWeek function.
ex9.pp contains an example of the DecodeDate function.
@ -20,3 +19,21 @@ ex16.pp contains an example of the IsLeapYear function.
ex17.pp contains an example of the MSecsToTimeStamp function.
ex18.pp contains an example of the Now function.
ex19.pp contains an example of the StrToDate function.
ex19.pp contains an example of the StrToDateTime function.
ex21.pp contains an example of the StrToTime function.
ex22.pp contains an example of the SystemTimeToDateTime function.
ex23.pp contains an example of the Time function.
ex24.pp contains an example of the TimeStampToDateTime function.
ex25.pp contains an example of the TimeToStr function.
ex26.pp contains an example of the CreateDir and RemoveDir function.
ex27.pp contains an example of the DiskFree function.
ex28.pp contains an example of the GetCurrentDir function.
ex29.pp contains an example of the SetCurrentDir function.
ex30.pp contains an example of the ChangeFileExt function.
ex31.pp contains an example of the DeleteFile function.
ex32.pp contains an example of the DoDirSeparators function.
ex33.pp contains an example of the ExpandFileName function.
ex34.pp contains an example of the ExtractFileName function.
ex35.pp contains an example of the ExtractRelativePath function.
ex36.pp contains an example of the FileAge function.
ex37.pp contains an example of the FileCreate function.

20
docs/sysutex/ex20.pp Normal file
View File

@ -0,0 +1,20 @@
Program Example20;
{ This program demonstrates the StrToDateTime function }
Uses sysutils;
Procedure TestStr (S : String);
begin
Writeln (S,' : ',DateTimeToStr(StrToDateTime(S)));
end;
Begin
Writeln ('ShortDateFormat ',ShortDateFormat);
TestStr(DateTimeToStr(Now));
TestStr('05-05-1999 15:50');
TestStr('5-5 13:30');
TestStr('5 1:30PM');
End.

18
docs/sysutex/ex21.pp Normal file
View File

@ -0,0 +1,18 @@
Program Example21;
{ This program demonstrates the StrToTime function }
Uses sysutils;
Procedure TestStr (S : String);
begin
Writeln (S,' : ',TimeToStr(StrToTime(S)));
end;
Begin
teststr (TimeToStr(Time));
teststr ('12:00');
teststr ('15:30');
teststr ('3:30PM');
End.

17
docs/sysutex/ex22.pp Normal file
View File

@ -0,0 +1,17 @@
Program Example22;
{ This program demonstrates the SystemTimeToDateTime function }
Uses sysutils;
Var ST : TSystemTime;
Begin
DateTimeToSystemTime(Now,ST);
With St do
begin
Writeln ('Today is ',year,'/',month,'/',Day);
Writeln ('The time is ',Hour,':',minute,':',Second,'.',MilliSecond);
end;
Writeln ('Converted : ',DateTimeToStr(SystemTimeToDateTime(ST)));
End.

9
docs/sysutex/ex23.pp Normal file
View File

@ -0,0 +1,9 @@
Program Example23;
{ This program demonstrates the Time function }
Uses sysutils;
Begin
Writeln ('The time is : ',TimeToStr(Time));
End.

19
docs/sysutex/ex24.pp Normal file
View File

@ -0,0 +1,19 @@
Program Example24;
{ This program demonstrates the TimeStampToDateTime function }
Uses sysutils;
Var TS : TTimeStamp;
DT : TDateTime;
Begin
TS:=DateTimeToTimeStamp (Now);
With TS do
begin
Writeln ('Now is ',time,' millisecond past midnight');
Writeln ('Today is ' ,Date,' days past 1/1/0001');
end;
DT:=TimeStampToDateTime(TS);
Writeln ('Together this is : ',DateTimeToStr(DT));
End.

9
docs/sysutex/ex25.pp Normal file
View File

@ -0,0 +1,9 @@
Program Example25;
{ This program demonstrates the TimeToStr function }
Uses sysutils;
Begin
Writeln ('The current time is : ',TimeToStr(Time));
End.

19
docs/sysutex/ex26.pp Normal file
View File

@ -0,0 +1,19 @@
Program Example26;
{ This program demonstrates the CreateDir and RemoveDir functions }
{ Run this program twice in the same directory }
Uses sysutils;
Begin
If Not FileExists('NewDir') then
If Not CreateDir ('NewDir') Then
Writeln ('Failed to create directory !')
else
Writeln ('Created "NewDir" directory')
Else
If Not RemoveDir ('NewDir') Then
Writeln ('Failed to remove directory !')
else
Writeln ('Removed "NewDir" directory');
End.

12
docs/sysutex/ex27.pp Normal file
View File

@ -0,0 +1,12 @@
Program Example27;
{ This program demonstrates the DiskFree function }
Uses sysutils;
Begin
Write ('Size of current disk : ',DiskSize(0));
Writeln (' (= ',DiskSize(0) div 1024,'k)');
Write ('Free space of current disk : ',Diskfree(0));
Writeln (' (= ',Diskfree(0) div 1024,'k)');
End.

9
docs/sysutex/ex28.pp Normal file
View File

@ -0,0 +1,9 @@
Program Example28;
{ This program demonstrates the GetCurrentDir function }
Uses sysutils;
Begin
Writeln ('Current Directory is : ',GetCurrentDir);
End.

12
docs/sysutex/ex29.pp Normal file
View File

@ -0,0 +1,12 @@
Program Example29;
{ This program demonstrates the SetCurrentDir function }
Uses sysutils;
Begin
If SetCurrentDir ('..') Then
Writeln ('Now in directory ',GetCurrentDir)
else
Writeln ('Change directory to .. failed.');
End.

19
docs/sysutex/ex30.pp Normal file
View File

@ -0,0 +1,19 @@
Program Example30;
{ This program demonstrates the ChangeFileExt function }
Uses sysutils;
Procedure testit (N,E : String);
begin
Write ('Changing "',n,'" with extension "',e,'" : ');
Writeln (ChangeFileExt(N,E));
end;
Begin
Testit ('report.txt','.pas');
Testit ('file','.txt');
Testit ('/path/file.pas','.pp');
Testit ('/path/file.pp.org','.new');
End.

18
docs/sysutex/ex31.pp Normal file
View File

@ -0,0 +1,18 @@
Program Example31;
{ This program demonstrates the DeleteFile function }
Uses sysutils;
Var
Line : String;
F,I : Longint;
Begin
F:=FileCreate('test.txt');
Line:='Some string line.'#10;
For I:=1 to 10 do
FileWrite (F,Line[1],Length(Line));
FileClose(F);
DeleteFile('test.txt');
End.

21
docs/sysutex/ex32.pp Normal file
View File

@ -0,0 +1,21 @@
Program Example32;
{ This program demonstrates the DoDirSeparators function }
{$H+}
Uses sysutils;
Procedure Testit (F : String);
begin
Writeln ('Before : ',F);
DoDirSeparators (F);
Writeln ('After : ',F);
end;
Begin
Testit (GetCurrentDir);
Testit ('c:\pp\bin\win32');
Testit ('/usr/lib/fpc');
Testit ('\usr\lib\fpc');
End.

19
docs/sysutex/ex33.pp Normal file
View File

@ -0,0 +1,19 @@
Program Example33;
{ This program demonstrates the ExpandFileName function }
Uses sysutils;
Procedure Testit (F : String);
begin
Writeln (F,' expands to : ',ExpandFileName(F));
end;
Begin
Testit('ex33.pp');
Testit(ParamStr(0));
Testit('/pp/bin/win32/ppc386');
Testit('\pp\bin\win32\ppc386');
Testit('.');
End.

23
docs/sysutex/ex34.pp Normal file
View File

@ -0,0 +1,23 @@
Program Example34;
{ This program demonstrates the ExtractFileName function }
{$H+}
Uses sysutils;
Procedure Testit(F : String);
begin
Writeln ('FileName : ',F);
Writeln ('Has Name : ',ExtractFileName(F));
Writeln ('Has Path : ',ExtractFilePath(F));
Writeln ('Has Extension : ',ExtractFileExt(F));
Writeln ('Has Directory : ',ExtractFileDir(F));
Writeln ('Has Drive : ',ExtractFileDrive(F));
end;
Begin
Testit (Paramstr(0));
Testit ('/usr/local/bin/mysqld');
Testit ('c:\pp\bin\win32\ppc386.exe');
Testit ('/pp/bin/win32/ppc386.exe');
End.

19
docs/sysutex/ex35.pp Normal file
View File

@ -0,0 +1,19 @@
Program Example35;
{ This program demonstrates the ExtractRelativePath function }
Uses sysutils;
Procedure Testit (FromDir,ToDir : String);
begin
Write ('From "',FromDir,'" to "',ToDir,'" via "');
Writeln (ExtractRelativePath(FromDir,ToDir),'"');
end;
Begin
Testit ('/pp/src/compiler','/pp/bin/win32/ppc386');
Testit ('/pp/bin/win32/ppc386','/pp/src/compiler');
Testit ('e:/pp/bin/win32/ppc386','d:/pp/src/compiler');
Testit ('e:\pp\bin\win32\ppc386','d:\pp\src\compiler');
End.

16
docs/sysutex/ex36.pp Normal file
View File

@ -0,0 +1,16 @@
Program Example36;
{ This program demonstrates the FileAge function }
Uses sysutils;
Var S : TDateTime;
fa : Longint;
Begin
fa:=FileAge('ex36.pp');
If Fa<>-1 then
begin
S:=FileDateTodateTime(fa);
Writeln ('I''m from ',DateTimeToStr(S))
end;
End.

31
docs/sysutex/ex37.pp Normal file
View File

@ -0,0 +1,31 @@
Program Example37;
{ This program demonstrates the FileCreate function }
Uses sysutils;
Var I,J,F : Longint;
Begin
F:=FileCreate ('test.dat');
If F=-1 then
Halt(1);
For I:=0 to 100 do
FileWrite(F,I,SizeOf(i));
FileClose(f);
F:=FileOpen ('test.dat',fmOpenRead);
For I:=0 to 100 do
begin
FileRead (F,J,SizeOF(J));
If J<>I then
Writeln ('Mismatch at file position ',I)
end;
FileSeek(F,0,0);
Randomize;
Repeat
FileSeek(F,Random(100)*4,0);
FileRead (F,J,SizeOf(J));
Writeln ('Random read : ',j);
Until J>80;
FileClose(F);
End.

View File

@ -330,7 +330,7 @@ Function DateTimeToTimeStamp(DateTime: TDateTime): TTimeStamp;
None.
\SeeAlso
\seef{DateTimeToFileDate}, \seef{SystemTimeToDateTime},
\seef{DateTimeToSystemTime}
\seep{DateTimeToSystemTime}
\end{function}
\latex{\inputlisting{sysutex/ex6.pp}}
@ -511,7 +511,7 @@ None.
Function IsLeapYear(Year: Word): boolean;
\Description
\var{IsLeapYear} returns \var{True} if \var{Year} is a leap year,
\var{False} otherwise
\var{False} otherwise.
\Errors
None.
\SeeAlso
@ -527,6 +527,9 @@ Function MSecsToTimeStamp(MSecs: Comp): TTimeStamp;
\Description
\var{MSecsTiTimeStamp} converts the given number of milliseconds to
a \var{TTimeStamp} date/time notation.
Use \var{TTimeStamp} variables if you need to keep very precise track of
time.
\Errors
None.
\SeeAlso
@ -566,183 +569,362 @@ The order of the digits (y/m/d, m/d/y, d/m/y) is determined from the
\var{ShortDateFormat} variable.
\Errors
On error (e.g. an invalid date or invalid character),
a \var{EConvertError} exception is raised.
an \var{EConvertError} exception is raised.
\SeeAlso
\seef{StrToTime}, \seef{DateToStr}n \seef{TimeToStr}.
\end{function}
\latex{\inputlisting{sysutex/ex19.pp}}
\latex{\inputlisting{sysutex/ex19.pp}}
\html{\input{sysutex/ex19.tex}}
\begin{function}{StrToDateTime}
\Declaration
Function StrToDateTime(const S: string): TDateTime;
\Description
\var{StrToDateTime} converts the string \var{S} to a \var{TDateTime} date
and time value. The Date must consist of 1 to three digits, separated by the
\var{DateSeparator} character. If two numbers are given, they
are supposed to form the day and month of the current year. If only
one number is given, it is supposed to represent the day of the
current month. (This is \em{not} supported in Delphi)
The order of the digits (y/m/d, m/d/y, d/m/y) is determined from the
\var{ShortDateFormat} variable.
\Errors
On error (e.g. an invalid date or invalid character),
an \var{EConvertError} exception is raised.
\SeeAlso
\seef{StrToDate}, \seef{StrToTime}, \seef{DateTimeToStr}
\end{function}
\latex{\inputlisting{sysutex/ex20.pp}}
\html{\input{sysutex/ex20.tex}}
\begin{function}{StrToTime}
\Declaration
Function StrToTime(const S: string): TDateTime;
\Description
\var{StrToTime} converts the string \var{S} to a \var{TDateTime} time
value. The time must consist of 1 to 4 digits, separated by the
\var{TimeSeparator} character. If two numbers are given, they
are supposed to form the hour and minutes.
\Errors
On error (e.g. an invalid date or invalid character),
an \var{EConvertError} exception is raised.
\SeeAlso
\seef{StrToDate}, \seef{StrToDateTime}, \seef{TimeToStr}
\end{function}
\latex{\inputlisting{sysutex/ex21.pp}}
\html{\input{sysutex/ex21.tex}}
\begin{function}{SystemTimeToDateTime}
\Declaration
Function SystemTimeToDateTime(const SystemTime: TSystemTime): TDateTime;
\Description
\var{SystemTimeToDateTime} converts a \var{TSystemTime} record to a
\var{TDateTime} style date/time indication.
\Errors
None.
\SeeAlso
\seep{DateTimeToSystemTime}
\end{function}
\latex{\inputlisting{sysutex/ex22.pp}}
\html{\input{sysutex/ex22.tex}}
\begin{function}{Time}
\Declaration
Function Time: TDateTime;
\Description
\var{Time} returns the current time in \var{TDateTime} format. The date
part of the \var{TDateTimeValue} is set to zero.
\Errors
None.
\SeeAlso
\seef{Now}, \seef{Date}
\end{function}
\latex{\inputlisting{sysutex/ex23.pp}}
\html{\input{sysutex/ex23.tex}}
\begin{function}{TimeStampToDateTime}
\Declaration
Function TimeStampToDateTime(const TimeStamp: TTimeStamp): TDateTime;
\Description
\var{TimeStampToDateTime} converts \var{TimeStamp} to a \var{TDateTime}
format variable. It is the inverse operation of \seef{DateTimeToTimeStamp}.
\Errors
None.
\SeeAlso
\seef{DateTimeToTimeStamp}, \seef{TimeStampToMSecs}
\end{function}
\latex{\inputlisting{sysutex/ex24.pp}}
\html{\input{sysutex/ex24.tex}}
\begin{function}{TimeStampToMSecs}
\Declaration
Function TimeStampToMSecs(const TimeStamp: TTimeStamp): comp;
\Description
\var{TimeStampToMSecs} converts {TimeStamp} to the number of seconds
since \var{1/1/0001}.
Use \var{TTimeStamp} variables if you need to keep very precise track of
time.
\Errors
None.
\SeeAlso
\seef{MSecsToTimeStamp}, \seef{TimeStampToDateTime}
\end{function}
For an example, see \seef{MSecsToTimeStamp}.
\begin{function}{TimeToStr}
\Declaration
Function TimeToStr(Time: TDateTime): string;
\Description
\var{TimeToStr} converts the time in \var{Time} to a string. It uses
the \var{ShortTimeFormat} variable to see what formatting needs to be
applied. It is therefor entirely equivalent to a
\var{FormatDateTime('t',Time)} call.
\Errors
None.
\SeeAlso
\end{function}
\latex{\inputlisting{sysutex/ex25.pp}}
\html{\input{sysutex/ex25.tex}}
\section{Disk functions}
\begin{functionl}{AddDisk (Linux only)}{AddDisk}
\Declaration
Function AddDisk (Const PAth : String) : Longint;
\Description
On Linux both the \seef{Diskfree} and \seef{Disksize} functions need a
file on the specified drive, since is required for the statfs system call.
These filenames are set in drivestr[0..26], and the first 4 have been
preset to :
\begin{description}
\item[Disk 0] \var{'.'} default drive - hence current directory is used.
\item[Disk 1] \var{'/fd0/.'} floppy drive 1.
\item[Disk 2] \var{'/fd1/.'} floppy drive 2.
\item[Disk 3] \var{'/'} \file{C:} equivalent of DOS is the root partition.
\end{description}
Drives 4..26 can be set by your own applications with the \var{AddDisk} call.
The \var{AddDisk} call adds \var{Path} to the names of drive files, and
returns the number of the disk that corresponds to this drive. If you
add more than 21 drives, the count is wrapped to 4.
\Errors
None.
\SeeAlso
\seef{DiskFree}, \seef{DiskSize}
\end{functionl}
\begin{function}{CreateDir}
\Declaration
Function CreateDir(Const NewDir : String) : Boolean;
\Description
\var{CreateDir} creates a new directory with name \var{NewDir}.
If the directory doesn't contain an absolute path, then the directory is
created below the current working directory.
The function returns \var{True} if the directory was successfully
created, \var{False} otherwise.
\Errors
In case of an error, the function returns \var{False}.
\SeeAlso
\seef{RemoveDir}
\end{function}
\latex{\inputlisting{sysutex/ex26.pp}}
\html{\input{sysutex/ex26.tex}}
\begin{function}{DiskFree}
\Declaration
Function DiskFree(Drive : Byte) : Longint;
\Description
\var{DiskFree} returns the free space (in bytes) on disk \var{Drive}.
Drive is the number of the disk drive:
\begin{description}
\item[0] for the current drive.
\item[1] for the first floppy drive.
\item[2] for the second floppy drive.
\item[3] for the first hard-disk parttion.
\item[4-26] for all other drives and partitions.
\end{description}
{\em Remark} Under \linux, and Unix in general, the concept of disk is
different than the \dos one, since the filesystem is seen as one big
directory tree. For this reason, the \var{DiskFree} and \seef{DiskSize}
functions must be mimicked using filenames that reside on the partitions.
For more information, see \seef{AddDisk}
\Errors
On error, \var{-1} is returned.
\SeeAlso
\seef{DiskSize}, \seef{AddDisk}
\end{function}
\latex{\inputlisting{sysutex/ex27.pp}}
\html{\input{sysutex/ex27.tex}}
\begin{function}{DiskSize}
\Declaration
Function DiskSize(Drive : Byte) : Longint;
\Description
\var{DiskSize} returns the size (in bytes) of disk \var{Drive}.
Drive is the number of the disk drive:
\begin{description}
\item[0] for the current drive.
\item[1] for the first floppy drive.
\item[2] for the second floppy drive.
\item[3] for the first hard-disk parttion.
\item[4-26] for all other drives and partitions.
\end{description}
{\em Remark} Under \linux, and Unix in general, the concept of disk is
different than the \dos one, since the filesystem is seen as one big
directory tree. For this reason, the \seef{DiskFree} and \var{DiskSize}
functions must be mimicked using filenames that reside on the partitions.
For more information, see \seef{AddDisk}
\Errors
On error, \var{-1} is returned.
\SeeAlso
\seef{DiskFree}, \seef{AddDisk}
\end{function}
For an example, see \seef{DiskFree}.
\begin{function}{GetCurrentDir}
\Declaration
Function GetCurrentDir : String;
\Description
\var{GetCurrentDir} returns the current working directory.
\Errors
None.
\SeeAlso
\seef{SetCurrentDir}, \seef{DiskFree}, \seef{DiskSize}
\end{function}
\latex{\inputlisting{sysutex/ex28.pp}}
\html{\input{sysutex/ex28.tex}}
\begin{function}{RemoveDir}
\Declaration
Function RemoveDir(Const Dir : String) : Boolean;
\Description
\var{RemoveDir} removes directory \var{Dir} from the disk.
If the directory is not absolue, it is appended to the current working
directory.
\Errors
In case of error (e.g. the directory isn't empty) the function returns
\var{False}. If successful, \var{True} is returned.
\SeeAlso
\end{function}
For an example, see \seef{CreateDir}.
\begin{function}{SetCurrentDir}
\Declaration
Function SetCurrentDir(Const NewDir : String) : Boolean;
\Description
\var{SetCurrentDir} sets the current working directory of your program
to \var{NewDir}. It returns \var{True} if the function was successfull,
\var{False} otherwise.
\Errors
In case of error, \var{False} is returned.
\SeeAlso
\seef{GetCurrentDir}
\end{function}
\latex{\inputlisting{sysutex/ex29.pp}}
\html{\input{sysutex/ex29.tex}}
\section{File handling functions}
\begin{function}{ChangeFileExt}
\Declaration
Function ChangeFileExt(const FileName, Extension: string): string;
\Description
\var{ChangeFileExt} changes the file extension in \var{FileName} to
\var{Extension}.
The extension \var{Extension} includes the starting \var{.} (dot).
The previous extension of \var{FileName} are all characters after the
last \var{.}, the \var{.} character included.
If \var{FileName} doesn't have an extension, \var{Extension} is just
appended.
\Errors
None.
\SeeAlso
\seef{ExtractFileName}, \seef{ExtractFilePath}, \seef{ExpandFileName}
\end{function}
\begin{function}{DeleteFile}
\Declaration
Function DeleteFile(Const FileName : String) : Boolean;
\Description
\var{DeleteFile} deletes file \var{FileName} from disk. The function
returns \var{True} if the file was successfully removed, \var{False}
otherwise.
\Errors
On error, \var{False} is returned.
\SeeAlso
\seef{CreateFile}, \seef{FileExists}
\end{function}
\latex{\inputlisting{sysutex/ex31.pp}}
\html{\input{sysutex/ex31.tex}}
\begin{procedure}{DoDirSeparators}
\Declaration
Procedure DoDirSeparators(Var FileName : String);
\Description
This function replaces all directory separators \var{'\' and '/'}
to the directory separator character for the current system.
\Errors
None.
\SeeAlso
\seef{ExtractFileName}, \seef{ExtractFilePath}
\end{procedure}
\latex{\inputlisting{sysutex/ex32.pp}}
\html{\input{sysutex/ex32.tex}}
\begin{function}{ExpandFileName}
\Declaration
Function ExpandFileName(Const FileName : string): String;
\Description
\var{ExpandFileName} expands the filename to an absolute filename.
It changes all directory separator characters to the one appropriate for the
system first.
\Errors
None.
\SeeAlso
\seef{ExtractFileName}, \seef{ExtractFilePath}, \seef{ExtractFileDir},
\seef{ExtractFileDrive}, \seef{ExtractFileExt}, \seef{ExtractRelativePath}
\end{function}
\latex{\inputlisting{sysutex/ex33.pp}}
\html{\input{sysutex/ex33.tex}}
\begin{function}{ExpandUNCFileName}
\Declaration
Function ExpandUNCFileName(Const FileName : string): String;
\Description
\var{ExpandUNCFileName} runs \seef{ExpandFileName} on \var{FileName}
and then attempts to replace the driveletter by the name of a shared disk.
\Errors
\SeeAlso
\seef{ExtractFileName}, \seef{ExtractFilePath}, \seef{ExtractFileDir},
\seef{ExtractFileDrive}, \seef{ExtractFileExt}, \seef{ExtractRelativePath}
\end{function}
@ -750,71 +932,134 @@ Function ExpandUNCFileName(Const FileName : string): String;
\Declaration
Function ExtractFileDir(Const FileName : string): string;
\Description
\var{ExtractFileDir} returns only the directory part of \var{FileName},
not including a driveletter. The directory name has NO ending directory
separator, in difference with \seef{ExtractFilePath}.
\Errors
None.
\SeeAlso
\seef{ExtractFileName}, \seef{ExtractFilePath}, \seef{ExtractFileDir},
\seef{ExtractFileDrive}, \seef{ExtractFileExt}, \seef{ExtractRelativePath}
\end{function}
\latex{\inputlisting{sysutex/ex34.pp}}
\html{\input{sysutex/ex34.tex}}
\begin{function}{ExtractFileDrive}
\Declaration
Function ExtractFileDrive(const FileName: string): string;
\Description
\var{Extract}
\Errors
\SeeAlso
\seef{ExtractFileName}, \seef{ExtractFilePath}, \seef{ExtractFileDir},
\seef{ExtractFileDrive}, \seef{ExtractFileExt}, \seef{ExtractRelativePath}
\end{function}
For an example, see \seef{ExtractFileDir}.
\begin{function}{ExtractFileExt}
\Declaration
Function ExtractFileExt(const FileName: string): string;
\Description
\var{ExtractFileExt} returns the extension (including the
\var{.}(dot) character) of \var{FileName}.
\Errors
None.
\SeeAlso
\seef{ExtractFileName}, \seef{ExtractFilePath}, \seef{ExtractFileDir},
\seef{ExtractFileDrive}, \seef{ExtractFileExt}, \seef{ExtractRelativePath}
\end{function}
For an example, see \seef{ExtractFileDir}.
\begin{function}{ExtractFileName}
\Declaration
Function ExtractFileName(const FileName: string): string;
\Description
\var{ExtractFileName} returns the filename part from \var{FileName}.
The filename consists of all characters after the last directory separator
character ('/' or '\') or drive letter.
The full filename can always be reconstucted by concatenating the result
of \seef{ExtractFilePath} and \var{ExtractFileName}.
\Errors
None.
\SeeAlso
\seef{ExtractFileName}, \seef{ExtractFilePath}, \seef{ExtractFileDir},
\seef{ExtractFileDrive}, \seef{ExtractFileExt},\seef{ExtractRelativePath}
\end{function}
For an example, see \seef{ExtractFileDir}.
\begin{function}{ExtractFilePath}
\Declaration
Function ExtractFilePath(const FileName: string): string;
\Description
\var{ExtractFilePath} returns the path part (including driveletter) from
\var{FileName}. The path consists of all characters before the last
directory separator character ('/' or '\'), including the directory
separator itself.
In case there is only a drive letter, that will be returned.
The full filename can always be reconstucted by concatenating the result
of \var{ExtractFilePath} and \seef{ExtractFileName}.
\Errors
None.
\SeeAlso
\seef{ExtractFileName}, \seef{ExtractFilePath}, \seef{ExtractFileDir},
\seef{ExtractFileDrive}, \seef{ExtractFileExt}, \seef{ExtractRelativePath}
\end{function}
For an example, see \seef{ExtractFileDir}.
\begin{function}{ExtractRelativepath}
\begin{function}{ExtractRelativePath}
\Declaration
Function ExtractRelativepath(Const BaseName,DestNAme : String): String;
Function ExtractRelativePath(Const BaseName,DestNAme : String): String;
\Description
\var{ExtractRelativePath} constructs a relative path to go from
\var{BaseName} to \var{DestName}. If \var{DestName} is on another drive
(Not on Linux) then the whole \var{Destname} is returned.
{\em Note:} This function does not exist in the Delphi unit.
\Errors
None.
\SeeAlso
\seef{ExtractFileName}, \seef{ExtractFilePath}, \seef{ExtractFileDir},
\seef{ExtractFileDrive}, \seef{ExtractFileExt},
\end{function}
\latex{\inputlisting{sysutex/ex35.pp}}
\html{\input{sysutex/ex35.tex}}
\begin{function}{FileAge}
\Declaration
Function FileAge(Const FileName : String): Longint;
\Description
\var{FileAge} returns the last modification time of file \var{FileName}.
The FileDate format can be transformed to \var{TDateTime} format with the
\seef{FileDateToDateTime} function.
\Errors
In case of errors, \var{-1} is returned.
\SeeAlso
\seef{FileDateToDateTime}, \seef{FileExists}, \seef{FileGetAttr}
\end{function}
\latex{\inputlisting{sysutex/ex36.pp}}
\html{\input{sysutex/ex36.tex}}
\begin{procedure}{FileClose}
\Declaration
Procedure FileClose(Handle : Longint);
\Description
\var{FileClose} closes the file handle \var{Handle}. After this call,
attempting to read or write from the handle will result in an error.
\Errors
None.
\SeeAlso
\seef{FileCreate}, \seef{FileWrite}, \seef{FileOpen}, \seef{FileRead},
\seef{FileTruncate}, \seef{FileSeek}
\end{procedure}
@ -822,8 +1067,18 @@ Procedure FileClose(Handle : Longint);
\Declaration
Function FileCreate(Const FileName : String) : Longint;
\Description
\var{FileCreate} creates a new file with name \var{FileName} on the disk and
returns a file handle which can be used to read or write from the file with
the \seef{FileRead} and \seef{FileWrite} functions.
If a file with name \var{FileName} already existed on the disk, it is
overwritten.
\Errors
If an error occurs (e.g. disk full or non-existent path), the function
returns \var{-1}.
\SeeAlso
\seef{FileClose}, \seef{FileWrite}, \seef{FileOpen}, \seef{FileRead},
\seef{FileTruncate}, \seef{FileSeek}
\end{function}
@ -831,8 +1086,12 @@ Function FileCreate(Const FileName : String) : Longint;
\Declaration
Function FileExists(Const FileName : String) : Boolean;
\Description
\var{FileExists} returns \var{True} if a file with name \var{FileName}
exists on the disk, \var{False} otherwise.
\Errors
None.
\SeeAlso
\seef{FileAge}, \seef{FileGetAttr}, \seef{FileSetAttr}
\end{function}
@ -840,11 +1099,25 @@ Function FileExists(Const FileName : String) : Boolean;
\Declaration
Function FileGetAttr(Const FileName : String) : Longint;
\Description
\var{FileGetAttr} returns the attribute settings of file
\var{FileName}. The attribute is a \var{OR}-ed combination
of the following constants:
\begin{description}
\item[faReadOnly] The file is read-only.
\item[faHidden] The file is hidden. (On \linux, this means that the filename
starts with a dot)
\item[faSysFile] The file is a system file (On \linux, this means that the
file is a character, block or FIFO file).
\item[faVolumeId] Volume Label. Not possible under \linux.
\item[faDirectory] File is a directory.
\item[faArchive] file is an archive. Not possible on \linux.
\end{description}
\Errors
In case of error, -1 is returned.
\SeeAlso
\seef{FileSetAttr}, \seef{FileAge}, \seef{FileGetDate}.
\end{function}
\begin{function}{FileGetDate}
\Declaration
Function FileGetDate(Handle : Longint) : Longint;
@ -860,6 +1133,8 @@ Function FileOpen(Const FileName : string; Mode : Integer) : Longint;
\Description
\Errors
\SeeAlso
\seef{FileClose}, \seef{FileWrite}, \seef{FileCreate}, \seef{FileRead},
\seef{FileTruncate}, \seef{FileSeek}
\end{function}
@ -869,6 +1144,8 @@ Function FileRead(Handle : Longint; Var Buffer; Count : longint) : Longint;
\Description
\Errors
\SeeAlso
\seef{FileClose}, \seef{FileWrite}, \seef{FileCreate}, \seef{FileOpen},
\seef{FileTruncate}, \seef{FileSeek}
\end{function}
@ -887,6 +1164,8 @@ Function FileSeek(Handle,Offset,Origin : Longint) : Longint;
\Description
\Errors
\SeeAlso
\seef{FileClose}, \seef{FileWrite}, \seef{FileCreate}, \seef{FileOpen}
\seef{FileRead}, \seef{FileTruncate}
\end{function}
@ -914,6 +1193,8 @@ Function FileTruncate(Handle,Size: Longint) : boolean;
\Description
\Errors
\SeeAlso
\seef{FileClose}, \seef{FileWrite}, \seef{FileCreate}, \seef{FileOpen}
\seef{FileRead}, \seef{FileSeek}
\end{function}
@ -923,6 +1204,8 @@ Function FileWrite(Handle : Longint; Var Buffer; Count : Longint) : Longint;
\Description
\Errors
\SeeAlso
\seef{FileClose}, \seef{FileCreate}, \seef{FileOpen}
\seef{FileRead}, \seef{FileTruncate}, \seef{FileSeek}
\end{function}