0

As I have understood it the command dir C:\kat\subkat\20*.* should result in a list of all files in C:\kat\subkat\ with 20 as the first characters in the filename. In my computer I don't get all files. However, I get all files with a date for latest change beginning with 20. Have anyone seen some thing similar? When trying to use this method for copying with XCOPY, I get an immense number of files copied. Very few of them are files in C:\kat\subkat\ with 20 as the first characters in the filename. What has happened? What can I do? I have Windows 7 on an HP Probook6470b.

Richard
  • 1
  • 1

1 Answers1

0

Dir command have a MS-DOS legacy, which carry a CP/M one. Dir command history

The behavior can be unexpected for files whose name contains spaces, have more than 12 characters, or the extension is longer than 3 characters.

And that's because the generated 8.3 short names This Rules for 8.3 short names gives a clue about how short names are generated, but is not exhaustive. Please see my example below for some hints

When the folder or computer searched with dir support short names, files whose short name respect the mask, will be included in the final result.

Moreover, the result include files whose short name contains characters included in the mask, even these characters are not part of the long name.

A classic example is the ~1(2,3..) suffix How affect short names the DIR result

This behavior can be stopped, by removing the support for short names.

Examples. Supposing your folder contains

aabb.xl
aa bb.xl
aabb.xls
aa bb.xls
aabb.xlsx
aa bb.xlsx
aabb.xlsxp
aa bb.xlsxp
aabb.xlsxpm
aa bb.xlsxpm

On my PC, this is the result of Example 1)

DIR a*.* /x
17.09.2015  10:35                 0 AABB~1.XL    aa bb.xl
17.09.2015  10:35                 0 AABB~1.XLS   aa bb.xls
17.09.2015  10:35                 0 AABB~3.XLS   aa bb.xlsx
17.09.2015  10:35                 0 AA3C12~1.XLS aa bb.xlsxp
17.09.2015  10:35                 0 AA96D4~1.XLS aa bb.xlsxpm
17.09.2015  10:35                 0              aabb.xl
17.09.2015  10:35                 0              aabb.xls
17.09.2015  10:35                 0 AABB~2.XLS   aabb.xlsx
17.09.2015  10:35                 0 AABB~4.XLS   aabb.xlsxp
17.09.2015  10:35                 0 AA84DD~1.XLS aabb.xlsxpm

Example 2)

DIR "*b*.xls" /x
aabb.xls
aa bb.xls
aabb.xlsx
aa bb.xlsx
aabb.xlsxp

Example 3)

DIR "*b*.xl?" /x
aabb.xl
aa bb.xl
aabb.xls
aa bb.xls
aabb.xlsx
aa bb.xlsx
aabb.xlsxp

Example 4)

DIR "*D*.xls" /x
aa bb.xlsxpm aka AA96D4~1.XLS
aabb.xlsxpm aka AA84DD~1.XLS

Example 5)

DIR "??????.xls" /x
aabb.xls
aa bb.xls aka AABB~1.XLS
aabb.xlsx aka AABB~2.XLS
aa bb.xlsx aka AABB~3.XLS
aabb.xlsxp aka AABB~4.XLS
Community
  • 1
  • 1
  • Thank you very much a comprehensive answer! Do you know any program I can use for copying and moving files, which works more as one would expect with long filenames? – Richard Sep 17 '16 at 18:14