Reputation: 1
I've just starting using python 2.7 and was using the following code to ascertain the path to a file:
import os, fnmatch
#find the location of sunnyexplorer.exe
def find_files(directory, pattern):
for root, dirs, files in os.walk(directory):
for basename in files:
if fnmatch.fnmatch(basename, pattern):
filename = os.path.join(root, basename)
yield filename
for filename in find_files('c:\users','*.sx2'):
print ('Found Sunny Explorer data in:', filename)
everthing seemed to be working fine until I tried to use the path and noticed an error. The program reports the path as:
c:\users\woody\Documents\SMA\Sunny Explorer
whereas the correct path is:
c:\users\woody\My Documents\SMA\Sunny Explorer
Upvotes: 0
Views: 2112
Reputation: 41940
All versions of MS Windows since Vista store a user's documents in C:\Users\%username%\Documents
by default.
However, they also include an NTFS junction point C:\Users\%username%\My Documents
which points to the same location for backward compatibility.
The problem is, as I understand it, that you can't work with junction points with standard POSIX calls, so Python will not be able to use them without some Windows-specific extension module.
See also this question on superuser.com.
Upvotes: 2