command-line / batch file to list all the jar files?

Posted on


I want to list all the jar files in subdirectories of a specified path, on a Windows computer, along with the file size & times.

dir /s gives me too much information. dir /s *.jar sort of does what I want, but gives me a bunch of information per-directory that I don’t care about. dir /b/s *.jar is brief but doesn’t give me the time or filesize.

Is there a command that will just list the jar files + filesize/time?


you could do this:

for /r %i in (*.jar) do echo  %~ti %~zi %i 

which will iterate over all dirs (including the current one) and echos out the *.jar names. It will also echo out the echo command, so you may want to pipe the output to a file:

for /r %i in (*.jar) do echo %~ti %~zi %i >> myJars.txt

or put it in a bat:

@echo off
for /r %%i in (*.jar) do echo %%~ti %%~zi %%i

note the double %‘s in the .bat version.

This command line works:

dir /s *.jar | find "jar"

It pipes the output of “dir” into the “find” command to filter it – filtering out lines not containing “jar” like the lines with “Directory”.

However it is only 99.9% bullet proof. If a folder contains
“jar” in its name AND this folder contains a jar file then
you need to filter that out:

dir /s *.jar | find "jar" | find /V "Directory of"

“/V” means that all lines NOT containing “Directory of” will
be printed on the screen.

The closest I was able to get to what you needed was

dir /p /s *.jar

This gives out the files’ directory locations, their size, and their date/timestamp.

Excluding paths:

for /r c:yourpath %i in (*.jar) do @echo %~nxi %~zi %~ti

Including paths:

for /r c:yourpath %i in (*.jar) do @echo %~i %~zi %~ti

Leave a Reply

Your email address will not be published.