Eryk Sun <eryk...@gmail.com> added the comment:

> Python 3.9.6 scan_dir returns filenotfound on long paths, 
> but os_walk does not.

This would be surprising. os.walk() has been implemented via os.scandir() since 
Python 3.5. Do you have a concrete example of the directory structure to test? 

> I see that many people on the internet have said to 
> change the working directory as a work around.  

Changing the working directory is a workaround in Unix, not Windows. Without 
long-path support, the working directory in Windows is limited to 258 (MAX_PATH 
- 2) characters.

Without long-path support, the workaround in Windows is to use an extended 
path, i.e. a Unicode path that's fully-qualified and normalized -- as returned 
by os.path.abspath() -- and prefixed by "\\\\?\\" or "\\\\?\\UNC\\" (e.g. 
r"\\?\C:\spam" or r"\\?\UNC\server\share\spam"). This allows the native path 
length limit of about 32760 characters. Some API functions and applications do 
not support extended paths. In particular setting an extended path as the 
working directory is unsupported and buggy, even if long-path support is 
enabled. But extended paths work fine with most file functions in the os and 
shutil modules, such as os.scandir(), os.stat(), os.open(), shutil.copytree(), 
and shutil.rmtree().

----------
nosy: +eryksun

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue46084>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to