I have an external drive that has a bunch of photos in folders. They are all image types (bmp, jpg, jpeg, png, pcx, tif, gif, etc.)
In PowerShell, DOS batch(CMD), Excel VBA or VB Script I need a script that can recursively go from the root and find each image and IF it has pixel dimensions, I need it to write the Path, FileName (or Path\FileName together) and then pipe, comma or tab delimited, list the Width, Height (or Width x Height).
So the output for example would be:
H:\My Photos\1998\JohnK.png|1024|768
H:\Photos2\BeachPhotos\1985\daytona01.jpg|640|480
something like that. I can work with different delimiters and and even handle the dimensions in 1024x768 format.
I found maybe 5 examples online for various languages and none of them worked.
This PowerShell script below ran for 2 hours from the root and I thought it worked but it never created an output file. I then ran it on 1 folder and it took a second to run and it created the output file but the file was blank.
param( $folder = "H:\", $outputFile = "D:\Desktop\imagedetails.txt" )
$objShell = New-Object -ComObject Shell.Application
$fileList = @()
$attrList = @{}
$details = ( "Dimensions" )
$objFolder = $objShell.namespace($folder)
for ($attr = 0 ; $attr -le 500; $attr++)
{
$attrName = $objFolder.getDetailsOf($objFolder.items, $attr)
if ( $attrName -and ( -not $attrList.Contains($attrName) ))
{
$attrList.add( $attrName, $attr )
}
}
dir $folder -Recurse -Directory | ForEach-Object{
$objFolder = $objShell.namespace($_.FullName)
foreach($file in $objFolder.items())
{
foreach( $attr in $details)
{
$attrValue = $objFolder.getDetailsOf($file, $attrList[$attr])
if ( $attrValue )
{
Add-Member -InputObject $file -MemberType NoteProperty -Name $("A_" + $attr) -value $attrValue
}
}
$fileList += $file
$fileList.Count
}
}
$fileList | Export-Csv $outputFile -Delimiter ','
$fileList | Format-Table
Any help would be appreciated.
If it will help to know WHY I need this, I can tell you exactly what I am doing. I ran the program AllDup against this drive and it found 84,000+ duplicate groups and when I click each group the program worked great. It found all the smaller versions of photos that I no longer want. I just want the larger originals.
I exported AllDup’s results to Excel and it’s great except it does not export the dimensions. Believe it or not larger dimension size does not always mean larger file size I found out. Plus you cannot go by larger file size alone to determine the best photo.
I am fairly experienced in Excel VBA (not enough to get the image dimensions off all images recursively though or even just the Dimensions of those files using a path/file list which I have.). I need the dimensions to add them to my Results spreadsheet for each image.
In AllDup, if I do it manually, in each Duplicate Group I first take the image(s) that have the largest dimensions. Then if there are 2 with the same largest dimension size, I choose to keep just the one of these 2 with the largest file size. The Export file does have the File Size. I just need to add the dimensions and I can write the VBA macro to automated the rest.
I do not want to click on and manually choose and back-up 84,000+ groups of images.
Before anyone recommends DupeGuru, do NOT use that program if you value your photos. I lost the only copies of many photos using this thinking I was keeping only the best version.
I DO however recommend the program DropIt for organizing photos by Date Taken, Camera Make and Model, etc. It will save you a lot of time.
So far AllDup is meeting my needs EXCEPT for exporting image Dimensions.