11

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?

1
  • 1
    You probably need to escape the backslashes in the file path so use two [\\] backslashes instead of one: wmic datafile where Name="C:\\[...]\\IMG_5443.JPG" get Name,FileType Commented Aug 13, 2017 at 19:53

3 Answers 3

8

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 available.

3
  • This looks fairly simple to use, I've got it running from within the PowerShell IDE. But I'm trying to run this from VBA, and I'm not sure how to either put this all together into a) 1 file to call or b) 1 line to execute. Mainly it's the whole "Loading into memory" part I'm not sure about, + the fact that I need to set ExecutionPolicy which seems to involve clicking on stuff. Any idea how I can put this all into a single executable file?
    – Greedo
    Commented Aug 14, 2017 at 9:52
  • 1
    @Greedo Sorry, I've never done that ... it might be worth you asking a new question.
    – DavidPostill
    Commented Aug 14, 2017 at 10:05
  • To anyone reading this, I never found out, but I read the function blurb and saw it was doing something that wasn't specific to Powershell, so I just wrote it in VBA instead.
    – Greedo
    Commented Aug 16, 2017 at 11:48
4

There are a lot of tools for the cmd line which can get/extract image metadata.

  1. IrfanView
  2. Exiftool
  3. nconvert

> "C\Program Files\IrfanView\i_view64.exe" *.jpg /info=Jpeg_Info.txt /fullinfo

Sample output (just 1 picture):

>type Jpeg_Info.txt
[Scan-100210-0002.jpg]
File name = Scan-100210-0002.jpg
Directory =
Compression = JPEG, quality: 90, subsampling ON (2x2)
Resolution = 300 x 300 DPI
Image dimensions = 2206 x 3264  Pixels (7.20 MPixels) (1.48)
Print size = 18.7 x 27.6 cm; 7.35 x 10.88 inches
Color depth = 16,7 Million   (24 BitsPerPixel)
Number of unique colors = 83260
Disk size = 918.01 KB (940.042 Bytes)
Current memory size = 20.61  MB (21.607.720 Bytes)
File date/time = 2010-02-10 / 21:59:07

- EXIF -
Make - Canon
Model - N650U
ExifOffset - 86
DateTimeDigitized - 2010:02:10 21:59:01

> exiftool  Scan-100210-0001.jpg
ExifTool Version Number         : 9.73
File Name                       : Scan-100210-0001.jpg
Directory                       : .
File Size                       : 884 kB
File Modification Date/Time     : 2010:02:10 21:21:28+01:00
File Access Date/Time           : 2010:02:10 21:21:22+01:00
File Creation Date/Time         : 2010:02:10 21:21:22+01:00
File Permissions                : rw-rw-rw-
File Type                       : JPEG
MIME Type                       : image/jpeg
JFIF Version                    : 1.01
Resolution Unit                 : inches
X Resolution                    : 300
Y Resolution                    : 300
Exif Byte Order                 : Little-endian (Intel, II)
Make                            : Canon
Camera Model Name               : N650U
Page Name                       : Reflective
Create Date                     : 2010:02:10 20:21:22
Image Width                     : 2202
Image Height                    : 3264
Encoding Process                : Baseline DCT, Huffman coding
Bits Per Sample                 : 8
Color Components                : 3
Y Cb Cr Sub Sampling            : YCbCr4:2:0 (2 2)
Image Size                      : 2202x3264

> nconvert -fullinfo Scan-100210-0001.jpg 2>Nul
** NCONVERT v6.88 (c) 1991-2016 Pierre-E Gougelet (Apr 29 2016/17:06:08) **
        Version for Windows Xp/Vista/7 x64  (All rights reserved)
** This is freeware software (for non-commercial use)
Scan-100210-0001.jpg : Success
    Format               : JPEG TrueColor (v1.1)
    Name                 : jpeg
    Compression          : JPEG
    Width                : 2202
    Height               : 3264
    Components per pixel : 3
    Bits per component   : 8
    Depth                : 24
    # colors             : 16777216
    Color model          : RGB
    Bytes Per Plane      : 6606
    Orientation          : Top Left
    Xdpi                 : 300
    Ydpi                 : 300
    Page(s)              : 1
    Metadata             : ( EXIF )
EXIF:
  Camera:
    Camera Manufacturer  (0x010f): Canon
    Camera Model         (0x0110): N650U
  Image:
    Date digitized       (0x9004): 2010:02:10 20:21:22

With more or less effort the output can be filtered to the relevant properties and formatted the way you want with batch files.

4

Without installing external programs: tooltipinfo.bat or imginfo.bat - just pass the file name (or path if it's not in the same directory) to get the information.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .