[Python-ideas] Add OS-dependent automatic glob support

random832 at fastmail.us random832 at fastmail.us
Mon Jan 5 03:41:55 CET 2015


On Sun, Jan 4, 2015, at 21:07, Steven D'Aprano wrote:
> Do all Windows apps call FindFirstFile?

Most Windows apps' only interaction with wildcards is via the system
file selection dialog.

Ultimately, FindFirstFile/FindNextFile is the only way to enumerate
files in a directory - it's the equivalent of opendir/readdir. You're
expected to pass in directory\* or *.* if you want to enumerate all
files in a directory with no filtering.

I think it's rare for programs not deliberately written to emulate some
other behavior or ported from unix (with canned implementations of
opendir, readdir, glob, and fnmatch being easier than rewriting
everything to use the windows functions) to implement their own wildcard
handling rather than using the Windows API - the C Runtime functions
findfirst/findnext date back to early DOS C compilers (the OS functions
were int 21,4E and 4F.)

> I know that. The point that Random raised is that some wildcards are 
> legal in Windows file names. 

Well, more specifically, that the square bracket is both allowed in
Windows filenames and not expected to be used as a wildcard, so there is
no escape mechanism (since the only standard wildcards are ? and *,
which are not allowed in filenames)

>Yes, and *all* wildcards are legal in 
> POSIX filenames, so whatever problems we have with escaping are going to 
> occur on both platforms, as you have already pointed out above.

Well, yes, except for the fact that escaping and quoting is handled by
the shell on POSIX.

My _main_ reason for mentioning it was to forestall objections involving
applying wildcards to double-quoted strings, since double quote does
_not_ normally escape wildcards on Windows.


More information about the Python-ideas mailing list