home *** CD-ROM | disk | FTP | other *** search
- { ****************************** PATHS.PAS *******************************}
- { These procedures perform various functions to paths under PCMSDos 2.0 }
- { They are designed to be $Included into one's Turbo PASCAL program }
- { Written by: Clark Walker }
- { CompuServe 76010,346 }
- { ************************************************************************}
-
- { ************************************************************************}
- { This procedure will get the current directory }
- { ************************************************************************}
- PROCEDURE CurrDir( Drive : CHAR ; { Drive A,B,C, etc }
- VAR Path : String80; { Current Path returned here }
- VAR Error : INTEGER); { See dos 2.0 manual pg D-14 }
- VAR
- I : INTEGER;
- BEGIN
- Error := 0;
- Regs.AX := $4700; { Dos function to get curr dir }
- Regs.DX := ORD(Drive) - ORD('A') + 1; { Dos uses 1,2,3.. not A,B,C.. }
- Regs.DS := SEG(Path); { Point to area to hold Path }
- Regs.SI := OFS(Path); { Func 47 use DS:SI }
- Regs.SI := Regs.SI + 1; { Point past string length byte}
- INTR($21,Regs); { Call Dos using interupt 21 }
- Error := Regs.AX AND $ff; { Error 15 = bad Drive }
- I := 1;
- WHILE Path[I] <> CHR(0) DO I := I + 1; { Dos puts chr(0) at end }
- Path[0]:=CHR(I-1); { Set length byte in string }
- END;
-
- { ************************************************************************}
- { This procedure will create a subdirectory }
- { ************************************************************************}
- PROCEDURE MkDir(VAR AsciiZ : String80; { Full Path (Drive:\Path) }
- VAR Error : INTEGER ); { See dos 2.0 manual pg D-14 }
- BEGIN
- Error := 0;
- Regs.AX := $3900; { Dos function to make dir }
- Regs.DS := SEG(AsciiZ); { Point to Drive:\Path param }
- Regs.DX := OFS(AsciiZ);
- Regs.DX := Regs.DX + 1; { Func 39 uses DS:DX }
- AsciiZ[LENGTH(AsciiZ)+1]:=CHR(0); { dos wants it to end in chr(0)}
- INTR($21,Regs); { Call Dos using interupt 21 }
- Error := Regs.AX AND $ff; { See dos manual Page D-14 }
- IF Error = 2 THEN Error := 0; { Dos reports 'file not found' }
- { .. Error (incorrectly) I hope}
- END;
-
- { ************************************************************************}
- { This procedure will delete a subdirectory }
- { ************************************************************************}
- PROCEDURE RmDir(VAR AsciiZ : String80; { Full Path (Drive:\Path) }
- VAR Error : INTEGER ); { See dos 2.0 manual pg D-14 }
- BEGIN
- Error := 0;
- Regs.AX := $3A00; { Dos function to remote dir }
- Regs.DS := SEG(AsciiZ); { Point to Drive:\Path param }
- Regs.DX := OFS(AsciiZ);
- Regs.DX := Regs.DX + 1; { Func 3A uses DS:DX }
- AsciiZ[LENGTH(AsciiZ)+1]:=CHR(0); { dos wants it to end in chr(0)}
- INTR($21,Regs); { Call Dos using interupt 21 }
- Error := Regs.AX AND $ff; { See dos manual Page D-14 }
- END;
-
- { ************************************************************************}
- { This procedure will change to a different directory }
- { ************************************************************************}
- { After changing directories, any access within Turbo or outside Turbo }
- { to the Drive in the AsciiZ string will result in this directory being }
- { accessed. }
- { ************************************************************************}
- PROCEDURE ChDir(VAR AsciiZ : String80; { Full Path (Drive:\Path) }
- VAR Error : INTEGER ); { See dos 2.0 manual pg D-14 }
- BEGIN
- Error := 0;
- Regs.AX := $3B00; { Dos function to change dir }
- Regs.DS := SEG(AsciiZ); { Point to Drive:\Path param }
- Regs.DX := OFS(AsciiZ);
- Regs.DX := Regs.DX + 1; { Func 3B uses DS:DX }
- AsciiZ[LENGTH(AsciiZ)+1]:=CHR(0); { dos wants it to end in chr(0)}
- INTR($21,Regs); { Call Dos using interupt 21 }
- Error := Regs.AX AND $ff; { See dos manual Page D-14 }
- END;
-
- { ************************************************************************}
- { This procedure will delete a file in a directory }
- { ************************************************************************}
- PROCEDURE DelFile(VAR AsciiZ : String80; { Full Path (Drive:\Path\file)}
- VAR Error : INTEGER ); { See dos 2.0 manual pg D-14 }
- BEGIN
- Error := 0;
- Regs.AX := $4100; { Dos function to del via dir }
- Regs.DS := SEG(AsciiZ); { Point to Drive:\Path param }
- Regs.DX := OFS(AsciiZ);
- Regs.DX := Regs.DX + 1; { Func 41 uses DS:DX }
- AsciiZ[LENGTH(AsciiZ)+1]:=CHR(0); { dos wants it to end in chr(0)}
- INTR($21,Regs); { Call Dos using interupt 21 }
- Error := Regs.AX AND $ff; { See dos manual Page D-14 }
- END;
-
- { ************************************************************************}
- { This procedure will rename a file using a directory Path }
- { ************************************************************************}
- { Using this procedure you can MOVE a file between directories keeping }
- { in mind the second (to) directory\file is on the same Drive. }
- { ************************************************************************}
- { Note: If you specify a Drive in Path it must be the same as that in }
- { AsciiZ. In fact, if it is not your current Drive you MUST specify a }
- { Drive. Note, You will get Error code 255 (invalid Drive) when you }
- { specify the Drive and it is not your current 'logged on' Drive. }
- { ************************************************************************}
- PROCEDURE RenFile(VAR AsciiZ : String80; { Full Path (Drive:\Path\file)}
- VAR Path : String80; { \Path\File.name or filename }
- VAR Error : INTEGER ); { See dos 2.0 manual pg D-14 }
- BEGIN
- Error := 0;
- Regs.AX := $5600; { Dos function to move files }
- Regs.DS := SEG(AsciiZ); { Point to Drive:\Path param }
- Regs.DX := OFS(AsciiZ);
- Regs.DX := Regs.DX + 1; { Point past length byte }
- Regs.ES := SEG(Path);
- Regs.DI := OFS(Path);
- Regs.DI := Regs.DI + 1;
- AsciiZ[LENGTH(AsciiZ)+1]:=CHR(0); { dos wants it to end in chr(0)}
- Path[LENGTH(Path)+1]:=CHR(0);
- INTR($21,Regs); { Call Dos using interupt 21 }
- Error := Regs.AX AND $ff; { See dos manual Page D-14 }
- END;
-
- { ************************************************************************}
- { This function will return your current disk Drive id (A,B,C, etc.). }
- { ************************************************************************}
- FUNCTION CurrDrive : CHAR; { A,B,C, etc. }
- BEGIN
- Regs.AX := $1900; { Dos function returns Drive }
- INTR($21,Regs);
- CurrDrive := CHR(LO(Regs.AX)+ORD('A')); { 0=A, 1=B, etc }
- END;
-
- { ************************************************************************}
- { This procedure will change your 'logged on disk' }
- { ************************************************************************}
- PROCEDURE chgdrive (Drive : CHAR); { A,B,C, etc. }
- BEGIN
- Regs.AX := $0E00; { Dos function changes Drive }
- Regs.DX := ORD(Drive) - ORD('A'); { Dos uses 0,1,2 not A,B,C }
- INTR($21,Regs);
- END;
-
- { ************************************************************************}
- { This function will return the free disk space on any Drive }
- { ************************************************************************}
- FUNCTION FreeSpace (Drive : CHAR) : REAL; { A,B,C, etc. }
- VAR
- AvailClusters,SectorsPerCluster,BytesPerSector : REAL;
- BEGIN
- Regs.AX := $3600; { Dos function for free space}
- Regs.DX := ORD(Drive) - ORD('A') + 1; { Dos uses 1,2,3 for A,B,C }
- INTR($21,Regs);
- { returns: BX=avail clusters DX=total clusters
- CX=bytes per sector AX=sectors per cluster }
- AvailClusters := Regs.BX;
- SectorsPerCluster := Regs.AX;
- BytesPerSector := Regs.CX;
- FreeSpace := AvailClusters * SectorsPerCluster * BytesPerSector;
- END;