How to get Desktop location?

On Unix or Linux: import os desktop = os.path.join(os.path.join(os.path.expanduser(‘~’)), ‘Desktop’) on Windows: import os desktop = os.path.join(os.path.join(os.environ[‘USERPROFILE’]), ‘Desktop’) and to add in your command: shutil.copy(txtName, desktop)

Changing MongoDB data store directory

The short answer is that the –dbpath parameter in MongoDB will allow you to control what directory MongoDB reads and writes it’s data from. mongod –dbpath /usr/local/mongodb-data Would start mongodb and put the files in /usr/local/mongodb-data. Depending on your distribution and MongoDB installation, you can also configure the mongod.conf file to do this automatically: # … Read more

Determining location of JVM executable during runtime

You could always just use os.name to check if the user is running Windows or not. That’ll work on OS X, Linux and Windows at String jvm_location; if (System.getProperty(“os.name”).startsWith(“Win”)) { jvm_location = System.getProperties().getProperty(“java.home”) + File.separator + “bin” + File.separator + “java.exe”; } else { jvm_location = System.getProperties().getProperty(“java.home”) + File.separator + “bin” + File.separator + “java”; … Read more

Write a file in a specific path in C++

Specify the full path in the constructor of the stream, this can be an absolute path or a relative path. (relative to where the program is run from) The streams destructor closes the file for you at the end of the function where the object was created(since ofstream is a class). Explicit closes are a … Read more

“invalid path 0 files copied” Error while using xcopy command

Original answer Remove the ending backslash from the source folder path C:\Windows\System32\xcopy.exe /Y “C:\Users\Ryan\Desktop\mmars_pub” “C:\Users\Ryan\Desktop\Dropbox\MMARS\mmars_pub\” edited 2015/10/01 While the original question used a literal path, and the indicated solution will solve the problem, there is another option. For literal paths and in cases where the path is inside a variable and could (or not) end … Read more

How can one get an absolute or normalized file path in .NET?

I would write it like this: public static string NormalizePath(string path) { return Path.GetFullPath(new Uri(path).LocalPath) .TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar) .ToUpperInvariant(); } This should handle few scenarios like uri and potential escaped characters in it, like file:///C:/Test%20Project.exe -> C:\TEST PROJECT.EXE path segments specified by dots to denote current or parent directory c:\aaa\bbb\..\ccc -> C:\AAA\CCC tilde shortened (long) paths … Read more

Check whether a path is valid in Python without creating a file at the path’s target

tl;dr Call the is_path_exists_or_creatable() function defined below. Strictly Python 3. That’s just how we roll. A Tale of Two Questions The question of “How do I test pathname validity and, for valid pathnames, the existence or writability of those paths?” is clearly two separate questions. Both are interesting, and neither have received a genuinely satisfactory … Read more