Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the current folder on Delphi?

How to change process current folder on Delphi?

like image 952
Dmitry Avatar asked Sep 27 '13 12:09

Dmitry


2 Answers

Both ways work: ChDir or SetCurrentDir. They both make the same Windows API call: SetCurrentDirectory.

If you use ChDir, an exception will be raised (in $I+ mode_) if the directory doesn't exist. So you'd want to handle the exception in that case (using try and except).

If you use SetCurrentDir, it will return false if the directory doesn't exist, and true if it was successful.

Given that SetCurrentDir is newer and ChDir is quite old, legacy (from DOS days), the former is preferred and easy to use as well.

like image 198
lurker Avatar answered Oct 17 '22 17:10

lurker


Call the SetCurrentDir function from the SysUtils unit.

Note that the current directory is not a system property, it is a property of the process. Each process has its own current directory.

like image 45
David Heffernan Avatar answered Oct 17 '22 18:10

David Heffernan