Viki
Viki

Reputation: 23

Get all the file's version inside a folder

I am trying to get the file version of all the files inside a folder which I managed to do (but not in a good way) but now I want to stick the folder name along with the version so I would know which version is for which folder. I am not very good in command line and only use it for some small tasks whenever I need it so my apology in advance.. Here is what I have done:

For /d %%a in (C:\high\low\*) Do (For /d %%* in (%%a) Do wmic datafile where name="%%~da\\high\\low\\%%~nx*\\bin\\Services.dll" get Version /value) and I get output as:

`Version=2.2.0.1 Version=2.2.0.4 Version=2.2.0.4....Version=2.2.0.4

there are 20 folders under C:\high\low and I want to go into the bin directory of each sub folder so I can see which folder has been upgraded and which one is not.

Edit
There are more than 20 folders and structure is like this:
C:\high\low\office.Services.Bolton\bin\Services.dll
C:\high\low\office.Services.Slough\bin\Services.dll
C:\high\low\office.Services.Hull\bin\Services.dll
.
.
.
C:\high\low\office.Services.Cosham\bin\Services.dll

I want to check the version number of Services.dll and need the output as:
Bolton - 2.2.0.1
Slough - 2.3.0.1
Hull - 2.5.0.1
.
.
.
Cosham - 2.0.0.0

Thanks in advance..

Upvotes: 2

Views: 1712

Answers (1)

user6811411
user6811411

Reputation:

Instead of stacking for /d you could do a dir /b/s to find all Services.dll and parse the nasty (cr,cr,lf) output of wmic with a for /f:

@Echo off&SetLocal EnableExtensions EnableDelayedExpansion
For /F "tokens=*" %%A in (
  'Dir /B/S C:\high\low\Services.dll ^|findstr /i "bin\\Services.dll$"'
) Do (
  Set "DLL=%%~fA"
  Set "DLL=!DLL:\=\\!"
  For /F "tokens=1* delims==" %%B in (
    'wmic datafile where name^="!DLL!" get Version /value^|findstr Version'
  ) Do For /f "delims=" %%D in ("%%C") Do Echo Version: %%D   %%~fA
)
  • The first For /f parses the output of the commamd inside the '' iterating through each line passed in %%A (I prefer upper case variables to better distinguish between lower case~ modifiers.
  • Since Dir will allow wildcards only in the last element I can't do a Dir /B/S C:\high\low\*\bin\Services.dll
  • To ashure I get only Services.dll in a bin folder I pipe dir output to findstr /i "bin\\Services.dll$ (findstr uses by default a limited RegEx so the \ has to be escaped with another one, the $ anchors the expression at the end of the line).
  • The wmic command needs the backslashes in the path also escaped what is possible with string substitution (works only with normal variables)
  • In a (code block) we need delayed expansion to get actual values for variables changed in the code block, so ! instead of % for framing the variable names
  • The 2nd For /f parses wmic output splitting at the equal sign, assigning content to var %%C
  • EDIT added another for /f to remove the wmic cr

Upvotes: 1

Related Questions