I need to extract the fileversion of certain DLL files of which I do not know the name. All I know is where the file that holds the fileversion is located and that its name is the same as the folder it is hiding beneath.
In truth it's something like this:
C:\inetpub\wwwroot\APPFolder\bin\files
(where the name of the Subfolder matches the name of the file in the bin folder)
After many tries (and a lot of failures), I've gone a bit back and forth, and I'm now leaning comfortably at this bit of code .... close, but no cigar:
Get-ChildItem -Path c:\temp\Documents -recurse -Filter *.dll | where-object{ (Get-ChildItem -Path c:\temp\Documents -recurse -Filter *.dll) -match $_.Directory.Name }
This code searches for all the files recursively under \temp\documents
and then matches the files in the folders, which is nice ... but not quite what I wanted. Also the code above gives the folders where the files that match the folders they are in and not only the matched file.
So ... any suggestions? There are more than one DLL file in the bin folder mentioned above which is part of why I need to select the one with the same name as the APPFolder.
Here is a code sample which will give you the full file path to the files you're looking for.
Breaking it down, we have:
This will search the current directory and its children recursively for all files that have a .dll file extension:
This will eliminate directories that end in .dll. Unlikely, but possible
This will filter it down to the DLL files that have a file name the same as the name of a directory above it in the path.
This will give you the full file path.
You can then follow the answer to this question here to get the FileVersion.