# Win32 - C - Read Command Line Directory

## Recommended Posts

aboeing    180
Hi, I seem to be having trouble in reading the directory in which I execute a command. (Win32 program). Example: C:\something> myprogram myargument if I then print out the string returned by GetCommandLine, I get: myprogram myargument if I print out the string from GetCurrentDirectory I get: C:\install_location_of_myprogram How can I get the directory from which I ran my program? (ie: C:\something) ? (I have tried reading the environment variable CD but that didnt work either) Thanks!

##### Share on other sites
blairhartley    187
Not sure why your call to GetCommandLine is not returning the fully qualified path for you... it does this fine for me.

However, you can use GetModuleFileName which should do what you want...

GetModuleFileName(GetModuleHandle(NULL), filename_buffer, buffer_length);

Hope that helps!