Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Turbo Pascal - <b> files pp 198</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
                                    FILES                             pp 198


 File Names:

          A file name in DOS consists of a path of directory names separated
          by backslashes followed by the file name.


          C:\Editor\Documents\Inventory.Doc


          The drive and path are optional, and if not specified, the file is
          assumed to be on the current drive and directory.
          The file name consists of a 1..8 charachter name followed by an
          optional 1..3 character file extent.




 Number of Files:

          The number of open files is controlled with the compiler F
          directive and the DOS Config.Sys file.  The default is 16.



 Extended File Size:

          MS-DOS supports files that are larger than can be represented by
          the MaxInt value, and therefore need an additional means of
          sizing and seeking.  The LongFileSize, LongFilePos, LongSeek
          functions are of type Real for this purpose.  They correspond to
          their Integer equivalents of FileSize, FilePos, Seek.






 Text Files:

          A text file is one which has the data delineated with a Cr/Lf
          terminator at the end of each line.  A text file is specifically
          declared as such.  The file buffer size is 128 bytes by default.
          Buffer size can be changed when the handle is declared.

       VAR
          FileVar : Text [$800];               { 2k buffer for text file    }
          StrVar  : String [80];               { String variable for file   }


       BEGIN
          Assign  (FileVar,'TestFile.Dat');    { Assign filename to handle  }
          ReWrite (FileVar)               ;    { Open the file              }
          WriteLn (FileVar,StrVar)        ;    { Write text to file         }
          Close   (FileVar)               ;    { Close the file             }
       END.


 Untyped Files:

          Any disk file may be declared untyped and accessed on a block by
          block basis, without regard to data type.  The declaration simply
          omits any Type for the file.


       VAR
          FileVar : File;


          Access to this file is done with the BlockRead and BlockWrite
          routines.  They read or write to a buffer that is a multiple
          of 128 bytes in size.  Block data movement is the fastest I/O
          possible on disk files, as no formatting need be done to the data.





 Typed Files:

          A typed file is one which has the data delineated by a record
          structure.  Each record is of the same length.  The file buffer
          size is determined by the length of the record.

          Only data of the same type as the file may be written to the file.
          Declaring a File of Integer and attempting to write a string to it
          will result in Error 44, Type Mismatch.

          A typed file may be accessed either sequentially or randomly.


 Sequential Access Files:

          Sequential access is starting with the first record and reading
          or writing in the ascending direction. (e.g. record #1, 2, etc.)
          All text files are sequential access files.

          The Read and Write functions work sequentially.
 Random Access Files:

          A random file is created in the same manner as the typed file.
          Since all records in the file are of a known length, they may be
          accessed in a random order using the Seek or LongSeek procedures.

          The record number is calculated as Record_Number x Record_Size.
          Record numbers start with zero.  Record_Number x 0 = 0 which is
          the top of the file.  Seek or LongSeek is then called and the
          file pointer is moved the appropriate number of bytes to be
          positioned at the desired record.

See Also: File File Of

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson