WindowsApi:GetCurrentDirectory
lastmod 2018-08-17created 2016-03-315 edits
Retrieves the current directory location.
Warning
When programming, you often place various files, such as configuration files, resource files like images and sounds, DBs, DLLs, and libraries, in the system folder or under the folder where the program is installed. In fact, isn't that almost always the case? Usually, once a program is installed, the folder containing the executable (exe) becomes the program's installation folder. When the program runs, CurrentDirectory is in most cases the same as the folder containing the executable (exe), but there are also many cases where it is not. And most importantly, CurrentDirectory can change at any time.
Cases where CurrentDirectory changes:
- When the current directory is changed directly with SetCurrentDirectory() or SetCurrentDir(VCL).
- When a file is selected and confirmed by executing a Dialog such as SaveDialog() or OpenDialog() (caution).
When getting the current directory location with GetCurrentDirectory(), a different path may be returned if the path was changed in a FILE dialog. Therefore, use GetModuleFileName() whenever possible.
Run-Time Library Reference
| Variable | Required header | Compatibility |
| | stdlib.h | Windows 95, Windows 98, Windows 98 Second Edition, Windows Millennium Edition, Windows NT 4.0, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003, Windows Server 2003 |