Dir command gives unexpected / unwanted results


  1. Posts : 7
    Windows 10
       #1

    Dir command gives unexpected / unwanted results


    If I open a command prompt window and give the command " dir *.xls", I also get all xlsm, xlsx, xlsq etc files. This behaviour is unwanted and illogical. it makes scripting hopelessly complex and unreliable. If I wanted those files, I would issue a "dir *.xls?" command.

    For the record: *.xlsq is NOT an existing Excel extension. I created an empty file with that extension to test this behaviour.

    Issuing the command "dir *.xl" gives me no results.

    Is there any way to make Windows list only .xls files, and not .xls? files?

    I suppose the same applies to Word and PowerPoint files. I have not tested this yet.
      My Computer


  2. Posts : 194
    Windows 10 Pro
       #2

    Don't know if this helps, but you get the desired result in Powershell - but as you say, not the standard cmd prompt.
      My Computer


  3. Posts : 3,276
    Win10
       #3

    Or you can try :
    dir *.xls | findstr /E ".xls"

    as shown here:

    How to list only .doc or .xls files with the Windows dir command in the cmd window? - Stack Overflow

    (from the above page: Microsoft is treating the string as a regex.)
    Last edited by das10; 26 Feb 2019 at 17:28.
      My Computers


  4. Posts : 16,966
    Windows 10 Home x64 Version 22H2 Build 19045.4170
       #4

    Or you could use a powershell line in your command window / batch file

    powershell dir *.xls

    Dir command gives unexpected / unwanted results-screenshot-30-.png
    [This is, in effect, the same as opening a PS window and running dir *.xls]

    Denis
      My Computer


  5. Posts : 1,255
    Windows 10 Pro
       #5

    Wildcard matching is more complex than is apparent. See this:
    https://blogs.msdn.microsoft.com/jer...ds-in-windows/
      My Computer


  6. Posts : 7
    Windows 10
    Thread Starter
       #6

    Thanks for the suggestions.
    I have as yet little experience with PowerShell. I still use commandline because I'm using it ever since the good old DOS days. E.G. to find all "old" excel files in a folder structure I would use something like:
    Code:
    dir /a/b/s *.xls > d:\check\excel.list
    With this new behaviour this would not work. To pipe it through "findstr" seems an exceptable solution in this scenario.
    DOS commands are often fast and simple for a lot of work that I do. Point is also that the computer should do what I ask, not interpret what it thinks I mean. (yes, I know, a computer can't think). If I want all excel files I woud give the "dir *.xls?", or even "dir *.xls*" command.
    The way it works now is illogical, and I don't understand why Microsoft has changed this behaviour.
      My Computer


  7. Posts : 16,966
    Windows 10 Home x64 Version 22H2 Build 19045.4170
       #7

    In case it was not clear above, in your commandline you can use this to get what you want
    powershell dir /a/b/s *.xls
    or
    powershell dir /a/b/s *.xls >d:\check\excel.list

    No additional 'powershell' work or any piping is required. As far as your tasks are concerned, you are merely using a longer term, powershell dir, in place of dir.

    Denis
      My Computer


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 10 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 00:11.
Find Us




Windows 10 Forums