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

6

0

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?

Jason S

Posted 2009-07-29T18:41:19.450

Reputation: 5 983

Answers

8

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.

akf

Posted 2009-07-29T18:41:19.450

Reputation: 3 781

To suppress the output of the 'echo' command, precede the command with '@'.

for /r %i in (*.jar) do @echo %~ti %~zi %i
 – bobbymcr  – 2009-08-23T16:59:32.173

1

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.

Peter Mortensen

Posted 2009-07-29T18:41:19.450

Reputation: 10 992

This is such a good answer. So strange how the accepted answer has 8 upvotes and this one had none! I gave you a +1. I looked at your profile. I see you committed to the Protein Modeling Area51 proposal. Sorry that it didn't succeed. I proposed a Materials Modeling site which covers protein modeling, but also other materials like solar cells, photo-voltaics, energy storage materials,

– user1271772 – 2020-02-15T02:11:23.510

new developments in batteries, and lighter or stronger materials for cars, airplanes, spaceships, etc. It would be very lovely to have you in the Private Beta! Please commit if you don't think it would be inconvenient! – user1271772 – 2020-02-15T02:12:15.243

0

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.

Isxek

Posted 2009-07-29T18:41:19.450

Reputation: 3 785

0

Excluding paths:

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

Including paths:

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

agtb

Posted 2009-07-29T18:41:19.450

Reputation: 111

0

If there is no particular reason for using the command line (like a batch script need)
You could just use the Explorer, Search to list *.jar files from the base folder.
You will get the size and date information and the list can be sorted in a few ways.

This will be a GUI solution.
I always wondered why Windows does not allow me to export such a search result to CSV/XLS/TXT.
All that hard work of sifting through the folders goes waste; cannot post-process the output.
Anyone has ideas on such an export to file?

nik

Posted 2009-07-29T18:41:19.450

Reputation: 50 788