[Tutor] What is the easiest way to ensure the current working directory is the same as the directory where the main program is saved?

Eryk Sun eryksun at gmail.com
Fri Jul 2 19:46:45 EDT 2021


On 7/2/21, Dennis Lee Bieber <wlfraed at ix.netcom.com> wrote:
>
> {Interesting: R seems to use both %userprofile% and
> %userprofile%\documents} Note that different apps used different "home"
> directories -- Linux would just be ~/.file to find the current user home.

In Windows, almost all of the Unix home-directory conventions are
either wrong or at least non-conventional. In the case of
"<home>\Documents", it's fundamentally wrong. The user's documents
directory is a known folder that's relocatable. It may even be set to
a directory on a remote share. One can't assume that the default
location in the profile directory is correct or even exists. Instead,
use the known-folder API to get the correct path. For example, query
the path of the user's documents folder via
SHGetKnownFolderPath(FOLDERID_Documents, ...).

> 	As I believe I mentioned, many programs ported from Linux to Windows
> DON'T bother to detect and user %appdata%. They store their files in (what
> in Linux) hidden "dot" files...  (the leading . doesn't make them hidden on
> Windows).

Creating dot files and directories in the user's profile directory
goes against the platform convention to use the per-user local or
roaming application-data directory. Personally, when applications
create these dot files it annoys me because there's no convention in
Windows shells to hide them. I can at least manually hide dot
directories. For dot files, on the other hand, I can't even manually
hide them since the hidden attribute is one of the special file
attributes that has to be conserved when overwriting a file, else the
open fails with access denied.


More information about the Tutor mailing list