Windos 7 DIR get too many files

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Erik Bachmann
Posts: 12
Joined: 25 Feb 2015 00:47
Location: Odense, Denmark

Windos 7 DIR get too many files

#1 Post by Erik Bachmann » 20 Mar 2015 04:28

This command took me by surprise:

Code: Select all

m:\flac\Adele\19>DIR /B "01*.*"
01 Adele - Daydreamer.flac
08 Adele - Right as Rain.flac

I did only expect the "daydreamer" line.
Likewise:

Code: Select all

m:\flac\Adele\21>DIR /B "01*.*"
01 Adele - Rolling in the Deep.flac
05 Adele - Set Fire to the Rain.flac

What am I missing here??

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Windos 7 DIR get too many files

#2 Post by foxidrive » 20 Mar 2015 04:33

DIR matches the short filename too. It starts with 01 in your case.

Code: Select all

dir /x


will show you.

Erik Bachmann
Posts: 12
Joined: 25 Feb 2015 00:47
Location: Odense, Denmark

Re: Windos 7 DIR get too many files

#3 Post by Erik Bachmann » 20 Mar 2015 23:23

Bingo! And DIR cannot surpress short file names - only surpress the long names.

So forfiles can do the trick:

Code: Select all

forfiles /s /M "*1*.*" /c "cmd /c ECHO:@RELPATH"

I'd whish that "Windos" could learn from *nix: Don't hide your tricks - do exactly what you're asked to do. :roll:

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Windos 7 DIR get too many files

#4 Post by foxidrive » 21 Mar 2015 06:21

You can also do this:

Code: Select all

DIR /B "01*.*"|findstr "^01"


It is a pretty glaring problem that should have been rectified with a switch to include or exclude short filenames.

Post Reply