How to change process current folder on Delphi?
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With