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.
LVL 1
mikeTmikeAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

dbruntonCommented:
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.
0
MotazCommented:
You can write your own function like this:

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

and you can call it as:

Writeln(GetDriveName(ParamStr(0));

Motaz

www.geocities.com/motaz1
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
MotazCommented:
Sorry the function is:
function GetDriveName(Path: string): string;
begin
  GetDriveName:= Copy(Path, 1, 2) + '\';
end;

I write it with Delphi :-)

Motaz
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Pascal

From novice to tech pro — start learning today.