Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you get the exact path to "My Documents"?

Tags:

python

windows

In C++ it's not too hard to get the full pathname to the folder that the shell calls "My Documents" in Windows XP and Windows 7 and "Documents" in Vista; see Get path to My Documents

Is there a simple way to do this in Python?

like image 210
Mark Ransom Avatar asked Oct 13 '10 19:10

Mark Ransom


People also ask

How do I find the path to a document?

Click the Start button and then click Computer, click to open the location of the desired file, hold down the Shift key and right-click the file. Copy As Path: Click this option to paste the full file path into a document. Properties: Click this option to immediately view the full file path (location).

What is the exact path to the Public Documents folder?

The Public folder is located in "C:\Users\Public", in all Windows versions. All user accounts registered in Windows have access to it. That's why it is named Public.

What is the path for this PC Documents?

Browsing to the Documents folder in Windows Explorer Open My Computer. Double-click the C: drive. In the C: drive, double-click the Documents and Settings folder. In Documents and Settings, double-click the folder for the users My Documents you want to see.

What is the directory for Documents?

The document directory is used by the system to save document files, picture files, report files and other files that are not a part of the database.


1 Answers

You could use the ctypes module to get the "My Documents" directory:

import ctypes
from ctypes.wintypes import MAX_PATH

dll = ctypes.windll.shell32
buf = ctypes.create_unicode_buffer(MAX_PATH + 1)
if dll.SHGetSpecialFolderPathW(None, buf, 0x0005, False):
    print(buf.value)
else:
    print("Failure!")

Source: http://bugs.python.org/issue1763#msg62242

like image 157
Josh Avatar answered Sep 17 '22 11:09

Josh