Windows – Command Line to return image properties

batch filecommand linewindows 10

I'm trying to return a text file containing some details about image files in a folder and its subfolders. Specifically:

  • File Path
  • Image extension
  • Image Dimensions
  • Date taken
  • Camera Model

These properties might not all be available for every image – I'm not sure if that will be a problem yet.

Getting the list of files is fine; DIR C:\[...]\FOLDER\*.* /S| (I think). It's the next part I'm not sure about; I've found info on other OSs, I've also heard WMIC suggested. I tried to use that with a test on a single file:

wmic datafile where Name="C:\[...]\IMG_5443.JPG" get Name,FileType > "C:\[...]\info.txt"

But it returns Error: Invalid query so I'm guessing WMIC doesn't work with images, or at least some of the arguments need to change.

I also notice, when I enter wmic datafile get/? that dimensions is not listed as one of the available properties. That's about as much troubleshooting as I know how to do.

So is there a way to return properties of an Image file (or list of files) in windows using the command line. If not, I'm open to anything that doesn't require installing additional software. Any suggestions?

Best Answer

How can I get the properties of an Image file in windows using the command line?

You can do this using PowerShell.

Commonly filled out metadata for image files contains the camera, the F-stop, resolution, and other useful information about the photo. This can be extremely useful for anyone who takes photos. The image metadata is easily found from the File tab for the photo by clicking Properties, then Details.

...

To use Windows PowerShell to examine this type of metadata means using the Shell.Application COM object, connecting to a file, and then walking through the metadata property bag. This technique is a bit cumbersome. Luckily, I can use the same function I wrote yesterday to accomplish this task.

Note the complete Get File Metadata function is available on the Script Center Repository.

...

Make sure to store results

Because it is possible that the script needs to iterate through thousands of photos, and for each photo it needs to search several hundred metadata attributes, the script will take some time to run. The best thing to do is to store the results in a variable. This will allow sorting and post collection processing of the data following the run.

The Get-FileMetaDataReturnObject.ps1 script contains a single function. The function is the Get-FileMetadata function. I load the function in the Windows PowerShell ISE, and run it to copy the function into memory. After I have done that, I call the function and pass it an array of folder paths. I get the array of folder paths by using the Get-ChildItem cmdlet. Here is the command that performs a recursive lookup of a folder named pics and pulls out the directory paths in that folder. This is a single line command that has wrapped.

$picMetadata = Get-FileMetaData -folder (Get-childitem E:\pics -Recurse -Directory).FullName

...

Write it to a file

Now that I know that the command produces the output I desire, I pipe the results to the Export-CSV cmdlet as shown here (this is a single-line command):

$picMetadata | 
Select 'camera model', dimensions, f-stop, 'flash mode', 'iso speed', 'exposure time', 'focal length', size, path |
Export-CSV -Path c:\fso\photoMetadata.csv -NoTypeInformation

Source Use PowerShell to Find Metadata from Photograph Files

Read the above source link to see what other metadata is avaialable.

Related Question