12

I am missing the wildcard character for directories. From linux I have in mind that one can define a path like this:

jslint scripts/**/*.js

which includes all js files from all descendent directories in the scripts directory tree.

jslint scripts/*/*.js

includes all direct subdirectories of scripts/.

In the windows command line this seems not to work. Is there any way to define the same?

0

2 Answers 2

8

There isn't a wildcard that works the way it does in Unix/Linux. In the Windows command line * or *.* will list files and directories in the current directory. But you can't do c:\blah\*\*

You can do:

    C:\tes>for /r %f in (*.mp3) do @echo mp3prog %f
    mp3prog C:\tes\a.mp3
    mp3prog C:\tes\mof.mp3
    mp3prog C:\tes\qw.mp3
    mp3prog C:\tes\y\a.mp3

C:\tes>

You see it lists all the commands it would execute. It goes through every file in c:\tes and all its subdirectories. So you could replace *.mp3 with *.js and mp3prog with jslint and that might give you what you want.

Remove the @echo to execute the commands instead of just displaying them. (Though it can be good to leave the @echo command in while debugging)

Either * or *.* in those brackets works fine.

Or from any directory

    C:\>for /r c:\tes %f in (*.*) do @echo mp3prog %f
    mp3prog c:\tes\103.gif
    mp3prog c:\tes\a.mp3
    mp3prog c:\tes\mof.mp3
    mp3prog c:\tes\oo.mpg
    mp3prog c:\tes\qw.mp3
    mp3prog c:\tes\t.mpg
    mp3prog c:\tes\ta.mpg
    mp3prog c:\tes\t_.mpg
    mp3prog c:\tes\u.mpg
    mp3prog c:\tes\uu.mpg
    mp3prog c:\tes\y\a.mp3
    
    C:\>

or

    C:\>for /f %f in ('dir c:\tes /s/b') do @echo mp3prog %f
    mp3prog c:\tes\103.gif
    mp3prog c:\tes\a.mp3
    mp3prog c:\tes\ff
    mp3prog c:\tes\gg
    mp3prog c:\tes\mof.mp3
    mp3prog c:\tes\oo.mpg
    mp3prog c:\tes\qw.mp3
    mp3prog c:\tes\t.mpg
    mp3prog c:\tes\ta.mpg
    mp3prog c:\tes\t_.mpg
    mp3prog c:\tes\u.mpg
    mp3prog c:\tes\uu.mpg
    mp3prog c:\tes\y
    mp3prog c:\tes\y\a.mp3
    
    C:\>
2
  • Remark, this solution only work if you want to use a recursive wildcard (searching in all subdirectories). For regular wildcard, this does not work.
    – Lærne
    Nov 28, 2019 at 12:28
  • @Lærne The question said "for all subdirectories or all descendent directories in windows commandline" So they wanted what you are calling "recursive". Also it's not the wildcard that is "recursive"(by which here you mean going through all subdirectories), it's the stuff around it that does that. If you do DIR *.* that lists all files in the current directory. If u do DIR /S *.* that lists all files in the current directory and all subdirectories of it. That's the same wildcard *.* but the DIR command has the /S option.
    – barlop
    May 17, 2023 at 14:58
1

In this particular case, all you need to do is specify the root directory name instead of using wildcards. At least, that is true for jshint, which is more popular now than jslint.

jshint scripts

Or:

cd scripts
jshint .

See also (which includes barlop's handy trick applied to jshint): https://stackoverflow.com/a/30114333/1593924

2
  • Thank you for the hint. My question was not targeting jslint/jshint though, it was just an example. It is a general question about the windows command line.
    – chiccodoro
    May 8, 2015 at 13:24
  • Right, but the answer I linked to does include several ways to address that more generally (including cygwin and powershell, and even a for loop).
    – Jon Coombs
    May 14, 2015 at 16:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .