New GitHub issue #102993 from GordonAitchJay:<br>
<hr>
<pre>
This is an issue experienced by a user on StackOverflow, so please excuse the lack of details and MRE. I'm hoping a Windows internals expert and/or a OneDrive dev can shed light on the situation.
[Why does os.walk() (Python) ignore a OneDrive directory depending on the number of files in it?](https://stackoverflow.com/questions/75743739/why-does-os-walk-python-ignore-a-onedrive-directory-depending-on-the-number)
The user has a directory which is a sync/shortcut of a SharePoint folder containing 897 files (all files can be opened, they are downloaded, not on-demand). When calling `os.listdir` with this directory, an exception is raised: `OSError: [WinError 87] The parameter is incorrect:`. However, if 2 files are deleted, it returns all the files (besides the 2 which were deleted). If the directory is copied somewhere outside the purview of OneDrive, `os.listdir` returns all 897 files.
Calling `win32file.FindFilesW` behaves the same as `os.listdir`. With 897 files it raises an exception: `error: (87, 'FindNextFileW', 'The parameter is incorrect.')`. After deleting 2 files, it returns all the files.
When calling `win32file.FindFilesIterator` when the directory has all 897 files, 443 files are yielded before the error occurs. `glob.glob()` is the same but doesn't yield `.` or `..` (as expected). Strangely, if only 1 file is deleted, `win32file.FindFilesIterator` yields only 25 files!
If the directory is copied to the local OneDrive root directory, `os.listdir` initially works (when OneDrive had just started uploading the files). However, after a couple of minutes, once a number of the files have been uploaded, `os.listdir` results in `OSError: [WinError 87] The parameter is incorrect:` again. Even before all files have synced, `win32file.FindFilesIterator` yields only 443 files again.
Explorer always shows the full list of files, and so does cmd's `dir`, and powershell's `ls` and `gci`.
Calling `NtQueryDirectoryFile` directly with ctypes always shows the full list of files
I'm fairly sceptical that CPython is at fault here, but I find it utterly bizarre that cmd's `dir`, and powershell's `ls` and `gci` work, which all call `FindNextFileW`, yet when CPython calls the same function it predictably returns prematurely.
</pre>
<hr>
<a href="https://github.com/python/cpython/issues/102993">View on GitHub</a>
<p>Labels: type-bug</p>
<p>Assignee: </p>