[next] [prev] [prev-tail] [tail] [up]

### 22.5 Disk functions

#### AddDisk (Linux only)

Declaration:
  Function AddDisk (Const PAth : String) : Longint;
Description:
  On Linux both the DiskFree (80) and DiskSize (81) 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 :

  Disk 0
    '.' default drive - hence current directory is used.
  Disk 1
    '/fd0/.' floppy drive 1.
  Disk 2
    '/fd1/.' floppy drive 2.
  Disk 3
    '/' C: equivalent of DOS is the root partition.

  Drives 4..26 can be set by your own applications with the AddDisk call.

  The AddDisk call adds 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.
See also:
  DiskFree (735), DiskSize (736)

#### CreateDir

Declaration:
  Function CreateDir(Const NewDir : String) : Boolean;
Description:
  CreateDir creates a new directory with name NewDir. If the directory doesn’t contain an absolute path, then the directory is created below the current working directory.

  The function returns True if the directory was successfully created, False otherwise.

Errors:
  In case of an error, the function returns False.
See also:
  RemoveDir (737)

Listing: sysutex/ex26.pp

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.

#### DiskFree

Declaration:
  Function DiskFree(Drive : Byte) : Int64;
Description:
  DiskFree returns the free space (in bytes) on disk Drive. Drive is the number of the disk drive:
  0
    for the current drive.
  1
    for the first floppy drive.
  2
    for the second floppy drive.
  3
    for the first hard-disk parttion.
  4-26
    for all other drives and partitions.

  Remark Under L I N U X, and Unix in general, the concept of disk is different than the D O S one, since the filesystem is seen as one big directory tree. For this reason, the DiskFree and DiskSize (81) functions must be mimicked using filenames that reside on the partitions. For more information, see AddDisk (734)

Errors:
  On error, -1 is returned.
See also:
  DiskSize (736), AddDisk (734)

Listing: sysutex/ex27.pp

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.

#### DiskSize

Declaration:
  Function DiskSize(Drive : Byte) : Int64;
Description:
  DiskSize returns the size (in bytes) of disk Drive. Drive is the number of the disk drive:
  0
    for the current drive.
  1
    for the first floppy drive.
  2
    for the second floppy drive.
  3
    for the first hard-disk parttion.
  4-26
    for all other drives and partitions.

  Remark Under L I N U X, and Unix in general, the concept of disk is different than the D O S one, since the filesystem is seen as one big directory tree. For this reason, the DiskFree (80) and DiskSize functions must be mimicked using filenames that reside on the partitions. For more information, see AddDisk (734)

Errors:
  On error, -1 is returned.
See also:
  DiskFree (735), AddDisk (734)

For an example, see DiskFree (735).

#### GetCurrentDir

Declaration:
  Function GetCurrentDir : String;
Description:
  GetCurrentDir returns the current working directory.
Errors:
  None.
See also:
  SetCurrentDir (737), DiskFree (80), DiskSize (81)

Listing: sysutex/ex28.pp

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

#### RemoveDir

Declaration:
  Function RemoveDir(Const Dir : String) : Boolean;
Description:
  RemoveDir removes directory 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 False. If successful, True is returned.
See also:

For an example, see CreateDir (734).

#### SetCurrentDir

Declaration:
  Function SetCurrentDir(Const NewDir : String) : Boolean;
Description:
  SetCurrentDir sets the current working directory of your program to NewDir. It returns True if the function was successfull, False otherwise.
Errors:
  In case of error, False is returned.
See also:
  GetCurrentDir (737)

Listing: sysutex/ex29.pp

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.

[next] [prev] [prev-tail] [front] [up]