I'm have an issue about displaying the files from a network drive on Windows.
path = "\\\\nexus\\File Server\\Technical\\MyDrive\\Software\\Releases\\%s\\%s\\" %(release, module)
where \\nexus\
is a network drive.
My main issue is given that a user enters correct variables, i'm unable to show the contents of the directory requested (the contents of 'module').
os.listdir(path)
The issue with the line above is that it returns a windows error [123] which is, a can not find directory error. This is because listdir() seems to double all the back slashes
resulting in :
"\\\\\\\\nexus\\File Server\\\\Technical\\\\MyDrive\\\\Software\\\\Releases\\\\release\\\\module\\\\"
print(glob.glob(path))
I didn't really know exactly how it works :P but it seems just to display the directory supplied and not the contents of the ending directory
\\nexus\File Server\Technical\MyDrive\Software\Releases\release\module\"
I've seen an os.walk
however im not sure how its works, in that how does it defines what is the base directory /directories and what is the rest of the path
Extra notes: The contents of 'module' will always be a zip file, also the directory will generally contain at maximum five zip files.
Open My Computer and click on the Tools menu option. From the drop down list, choose Map Network Drive. Pick a drive letter that you want to use to access the shared folder and then type in the UNC path to the folder. UNC path is just a special format for pointing to a folder on another computer.
Double-click the name of the computer from which the folder you want to open is being shared. Select a folder. Double-click the folder you want to open. Enter a username and password if prompted.
Click File Explorer.Click This PC in the left side shortcut menu. Click Computer > Map network drive > Map network drive to enter Mapping wizard. Confirm drive letter to use (next available shows up by default).
Just tested on my XP PC, Python 2.7, SMB share \\myshare
os.listdir('\\\\myshare') # Fails with "WindowsError: [Error 53] The network path was not found"
os.listdir('\\\\myshare/folder') # Succeeds
I think some of the confusion could be caused by WindowsError showing the repr()
of the path, rather than the actual path -
>>> repr(path)
"'\\\\myshare'"
>>> str(path)
'\\myshare'
If this is a Python 3 & unicode problem, I suggest trying to fix the string first:
path = "\\\\myshare\folder"
path = bytes(path, "utf-8").decode("unicode_escape")
print os.listdir(path)
(unfortunately I can't test this since I don't have Python 3 installed, but please let me know if it works and I'll edit my answer)
This one worked for me:
os.listdir('\\\\server\folder\subfolder\etc')
(with Python 2.7 32b on Win7 64b)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With