Link to home
Start Free TrialLog in
Avatar of mikeTmike
mikeTmike

asked on

Finding program Drive

Lets say when i compile the program it is CDI.exe, now with in this program I want a function wich i can execute.

if the program is at "C:\mydir\CDI.exe" I want this function to return "C:\" and if it is at "D:\mydir\CDI.exe" it is to return "D:\"

I want the function to return what drive the executable is on.
Avatar of dbrunton
dbrunton
Flag of New Zealand image

var
 which_drive : integer
 mydrive : string;

begin
  which_drive := 0;
  getdrive(whcih_drive, mydrive);
  writelnl('The drive is , mydrive);
end.

OR if you are using DOS 3.0 or higher

Writeln(ParamStr(0));

Note that I have submitted this as an answer.  Feel free to unlock the question if it is not suitable.
ASKER CERTIFIED SOLUTION
Avatar of Motaz
Motaz

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Motaz
Motaz

Sorry the function is:
function GetDriveName(Path: string): string;
begin
  GetDriveName:= Copy(Path, 1, 2) + '\';
end;

I write it with Delphi :-)

Motaz