While technically a network shortcut is a file, it prevents os.walk()
from traversing the directory. I've created a shortcut that maps C:\Data\Sale
to \\\filesrv\saledata
. I run the script:
import os
dir = "C:\Data"
for root, dirs, files in os.walk(dir, topdown=False):
for name in files:
print("file")
print(os.path.join(root, name))
for name in dirs:
print("directory")
print(os.path.join(root, name)) </code>
and I get:
file
C:\Data\Sale
No internals of \\filesrv\saledata
are listed. How can I make os.walk()
work with a Windows shortcut? UNC path isn't working either. Thanks in advance.
It's a known bug. Here you can find more information
https://bugs.python.org/issue1578269
Does Python os.walk(...,followlinks=True) work in WIndows (Vista)?
It turns out a way for os.walk to access a remote directory is to create a mapping using "net use" command: net use z: \... . Then os.walk can traverse through that.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.