← Go Back

How to Get Documents Folder Path in Windows

On Windows, the %userprofile% environment variable contains the path to the user's folder, which can be expanded using the os.path.expandvars() function.

>>> import os
>>> os.path.expandvars("%userprofile%")

(In this case, pcuser is the user name.)

In more recent versions of Windows, the "Documents" folder is normally located right under %userprofile%. Thus, the following code could be used to get its path:

>>> os.path.expandvars("%userprofile%\\Documents")

windows os.path

🐍 You might also find interesting: