6.1.4.2 file Positioning
Seek: Move the current position of the file to the specified section
Filepos: Returns the current location of the file
Eoln: Return line End Flag
EOF: Return file End Flag
FileSeek: Change the position of the current file pointer
The difference between seek and FileSeek is: 1. Seek is used only for recording files; 2. The FileSeek parameter is the file handle, offset, and start position. Where the starting position has the first file, the current position, the end of the file three choices. The argument for seek is a file variable, an offset, and the offset is positioned from the beginning of the file. 3. The offset of the FileSeek is computed in bytes, and seek is moved according to the record number.
Seek, Filepos only for recording files. However, any file can be considered a byte-based record file. The following procedure represents their use.
{The design interface for this example is a form that contains a topendialog part.} }
Uses Dialogs;
Var
F:file of Byte;
Size:longint;
s:string;
Y:integer;
Begin
If Opendialog1.execute Then
Begin
AssignFile (f, opendialog1.filename);
Reset (f);
Size: = FileSize (f);
S: = ' File size in bytes: ' + inttostr (size);
Y: = 10;
Canvas.textout (5, Y, S);
Y: = y + canvas.textheight (S) + 5;
S: = ' seeking halfway into file ... ';
Canvas.textout (5, Y, S);
Y: = y + canvas.textheight (S) + 5;
Seek (f,size Div 2);
S: = ' Position is now ' + INTTOSTR (Filepos (f));
Canvas.textout (5, Y, S);
CloseFile (f);
End
End.
6.1.4.3 file deletion and truncation
Erase: Deletes a file that exists
DeleteFile: Delete a file
Truncate: Truncate files from the current location of the file
The difference between erase and DeleteFile is that erase takes a file variable as a parameter and causes an exception when the file cannot be deleted, DeleteFile returns False when the file is not present or cannot be deleted, without causing an exception.
6.1.4.4 File name action
Rename: File Rename, file variable as action object
RenameFile: File name renamed, parameter is the original name of the file and new names
Changefileext: Changing the file name extension
Expandfilename: Return file full path name
Extractfileext: Returns the file name extension
Extractfilename: Returns the filename from the full path name
Extractfilepath: Returns the path to a specific file
6.1.4.5 file Properties
Filegetattr: Returning file properties
Filesetattr: Setting file properties
6.1.4.6 file Status
FileSize: Returns the size of the file object
IOResult: Returns the status of the last I/O operation
FileExists: Detects if a file exists
6.1.4.7 file Date
Datetimetofiledate: Convert Delphi date format to DOS date format
Filedatetodatetime: Convert the DOS date format to Delphi date format
Filegetdate: Returns a DOS date timestamp for a file
Filesetdate: Set the file's DOS date time stamp
6.1.4.8 file reading and writing
READ,READLN: Reading variables from text or record files
Write: Writes the specified variable to a text or record file
Writeln: Writes the specified variable to a text file and writes a line end flag
Fileread: Reading variables from a specified file
FileWrite: Write data to the specified file
Fileread and FileWrite are the object of the file handle, mainly for internal use of the system.
6.1.4.9 Directory Operations
MkDir: Create subdirectories of current directory
ChDir: Changing the current directory
Getdir: Returns the current directory for a specific disk
RmDir: Delete an empty directory
6.1.4.10 Disk Operations
Diskfree: Back to disk free space
DiskSize: Returns the size of a specific disk
6.1.4.11 File Lookup
FileSearch: Find out if a particular file exists in the directory
FindFirst: Finds the first file in the directory that matches the given file name (which can contain a match) and the property set
FindNext: Returns the next file that meets the criteria
FindClose: Abort a findfirst/findnext sequence
For more detailed information about the file management standard process/function, please consult the Delphi related Help topics. Most of the above processes are followed by an application, which the reader can use.
The process/function of the file is divided into two topics in Delphi's online Help assistance system: I/O routine and file_management routine. The former mostly takes the file variable as the manipulation object, while the latter mostly takes the file name or the file handle as the manipulation object. In order to facilitate the use of readers, we have reclassified by function. The following section mainly applies the process under the I/O routine theme, while in the fourth section The synthesis example mainly applies the process under the File_management routine theme.
In addition, Windows provides a number of API functions for file management. Although in general, using the functions provided by Delphi is enough to solve the problem, sometimes you still need to use the Windows API. In (6.4.4.2) we use the Windows API function GetDriveType. For information about Windows API functions, please refer to the relevant data, which is not covered here.