Changing the Current Working Directory in a Console Application

· Jan 31, 10:54 AM

The function SpecialFolder.CurrentWorkingDirectory provides a reference to the current working directory of your process. But there is no method built into REALbasic for changing the current working directory. The function chdir from the standard C library contains the method you need.

#if targetMacOS
  const libc = "System.framework"
#else
  const libc = "/usr/lib/nptl/libc.so"
#endif
 
soft declare function chdir lib libc (path as CString) as Integer

chdir returns 0 if it is successful, or -1 if it fails.

---

Commenting is closed for this article.