home-directory

Node.js - Find home directory in platform agnostic way

99封情书 提交于 2019-11-26 11:53:38
问题 Process.platform returns \"win32\" for Windows. On Windows a user\'s home directory might be C:\\Users[USERNAME] or C:\\Documents and Settings[USERNAME] depending on which version of Windows is being used. On Unix this isn\'t an issue. 回答1: As mentioned in a more recent answer, the preferred way is now simply: const homedir = require('os').homedir(); [Original Answer] : Why not use the USERPROFILE environment variable on win32? function getUserHome() { return process.env[(process.platform ==

How to get the home directory in Python? [duplicate]

扶醉桌前 提交于 2019-11-26 05:40:29
This question already has an answer here: How to find the real user home directory using python? 9 answers I need to get the location of the home directory of the current logged-on user. Currently, I've been using the following on Linux: os.getenv("HOME") However, this does not work on Windows. What is the correct cross-platform way to do this? dcolish You want to use os.path.expanduser . This will ensure it works on all platforms from os.path import expanduser home = expanduser("~") If you're on Python 3.5+ you can use pathlib.Path.home() : from pathlib import Path home = str(Path.home()) 来源:

How to find the real user home directory using python?

拟墨画扇 提交于 2019-11-26 02:56:56
问题 I see that if we change the HOME(linux) or USERPROFILE(windows) environmental variable and run a python script, it returns the new value as the user home when I tried, os.environ[\'HOME\'] os.exp Is there any way to find the real user home directory without relying on the environmental variable? edit: Here is a way to find userhome in windows by reading in the registry, http://mail.python.org/pipermail/python-win32/2008-January/006677.html edit: One way to find windows home using pywin32,

How to get the home directory in Python? [duplicate]

我的未来我决定 提交于 2019-11-26 01:09:50
问题 This question already has answers here : How to find the real user home directory using python? (9 answers) Closed 4 years ago . I need to get the location of the home directory of the current logged-on user. Currently, I\'ve been using the following on Linux: os.getenv(\"HOME\") However, this does not work on Windows. What is the correct cross-platform way to do this? 回答1: You want to use os.path.expanduser. This will ensure it works on all platforms from os.path import expanduser home =

What is the best way to find the users home directory in Java?

谁说我不能喝 提交于 2019-11-25 23:43:57
问题 The difficulty is that it should be cross platform. Windows 2000, XP, Vista, OSX, Linux, other unix variants. I am looking for a snippet of code that can accomplish this for all platforms, and a way to detect the platform. Now, you should be aware of bug 4787931 that user.home does not work correctly, so please do not provide me of textbook answers, I can find these myself in the manuals. 回答1: The bug you reference (bug 4787391) has been fixed in Java 8. Even if you are using an older version