Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Current Working Directory

Status
Not open for further replies.

Sherak

Programmer
Sep 1, 2003
83
GB
I have a program in which I store files in the same directory as the exe. I have a "open dialogue" in the prog and when I go to get files from other directorys, the Current Working Directory is changed to path of the file I get so when I try to open files in the programs root directory it cant find them, where is this string stored and how can I manipulate it ?
 
GetCurrentDirectory(nBufferLength, lpBuffer); find the current directory you use

To get programs directory use
GetModuleFileName( GetModuleHandle(0), lpFilename, nSize);

Ion Filipski
1c.bmp
 
I had the same problem than you, what I didi was to get the exe file path and the I call the libraries with the full path something like this

first get the exe file path

Ansistring FullPath = ExtractFilePath(Application->ExeName);

then use the absolute path with your files

Note:
Remember to add a "\" before the full path and your files

--- LastCyborg ---
 
Another solution is to store the program directory when the program starts. Then always say:
AnsiString CurDir = GetCurrentDir();
SetCurrentDir(ProgramDir);
Manipulate those files.
SetCurrentDir(CurDir);
 
>Supernat03
if you start program from command line and you are in some directory, your solution will not work in most cases. You will get only the directory from where you have started the program. The same thing if you start your program from a shortcut.

Ion Filipski
1c.bmp
 
Thanks everyone for you help, It is a Win32 app and I have resolved it by using AnsiString = GetCurrentDir(), then using the open/save dialogue and then reseting by using SetCurrentDir(AnsiString);

Thanks again.......
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top