1

In batch file scripts and the doc pages (e.g. here) I often see *.* as (I guess) a way to specify multiple folder/ file names. My question is: How exactly this string *.* is interpreted by cmd.exe?

I know that specify folder/ file names two special characters can be used:

  1. * means any number of character (including zero)
  2. ? one character

So *.txt would mean all files with extension .txt in the current directory. In light of this, I would read *.* as any folder/file name that has . (dot) in it.

Why then when I run DIR *.* in a folder that has only a subfolder named folder and a file named script.txt, it displays folder and script.txt instead of just showing script.txt?

aschipfl
  • 33,626
  • 12
  • 54
  • 99
zesy
  • 481
  • 5
  • 12
  • 1
    `cmd.exe` does not interpret `*.*` or any other wildcard pattern at all. It passes the string to the appropriate Windows file API function. I recommend to read the Microsoft documentation about [Naming Files, Paths, and Namespaces](https://learn.microsoft.com/en-us/windows/win32/fileio/naming-a-file) and [FindFirstFileW function](https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-findfirstfilew) and [FindNextFileW function](https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-findnextfilew). – Mofi Nov 15 '22 at 16:18
  • 1
    Take a look at this Super User thread: [How does the Windows RENAME command interpret wildcards?](https://superuser.com/q/475874) (regarding just the source mask for the `dir` command, for instance) Most internal commands and many external ones behave like that… – aschipfl Nov 15 '22 at 19:47
  • Is `?` not generally `0` or `1` character? With `where.exe`, it is `1` character only, but I'm unaware of another utility which has that ’quirk’. – Compo Nov 15 '22 at 21:38
  • @aschipfl if I read the thread correctly, it means that `*.*` can also match e.g. a name `aaa` because `.*` in `*.*` can match nothing. Scary to read at the beginning of the thread "These rules were discovered after extensive TESTING..." – zesy Nov 15 '22 at 21:40
  • If I wanted to use `Dir` to list files and/or directories, I'd just use `Dir` with no glob at all! (At the very least simply `Dir *` should suffice.) – Compo Nov 15 '22 at 21:44
  • @Compo I would do the same, but I am still curious about the logic behind `*.*`. – zesy Nov 15 '22 at 21:59
  • These masks come from ages where file names consisted of an 8-character base name and a 3-character extension, the so-called 8.3 file names; with that in mind, the wildcards may make more sense. Anyway, `*.*` and `*` are usually equivalent, with `.*` meaning every extension, even a blank one. `?` usually means one character, except at the end, it may also mean none (e. g., `???` matches file names with up to 3 characters). However, some commands (like `where` or `forfiles`) have got their own wildcard parsing rules, which makes the whole thing quite complicated… – aschipfl Nov 16 '22 at 08:39
  • Not enough, there are even undocumented wildcards, namely `<` (similar to `*`) and `>` (similar to `?`) – see also [Check if file with pattern exist](https://stackoverflow.com/a/34206104) and [FindFirstFile undocumented wildcard or bug?](https://stackoverflow.com/a/24193649) for more information about them… – aschipfl Nov 16 '22 at 08:47
  • 1
    Also refer to this Super User thread concerning wildcards: [Why does `dir *.*` give me all files and folders?](https://superuser.com/q/1193102) – aschipfl Nov 16 '22 at 08:55
  • files in Win32 namespace always contain a hidden dot at the end, so `*.*` always match all files, unless you use PowerShell – phuclv Nov 20 '22 at 15:41

0 Answers0