ExifTool Forum

General => Other Discussion => Topic started by: Chris S on March 27, 2023, 11:27:25 PM

Title: MacOS shell command to return image sizes & paths, but excluding certain folders
Post by: Chris S on March 27, 2023, 11:27:25 PM
I would like to get -MacOS:MDItemLogicalSize, but retrieving this tag is a bit slow with ExifTool. (The -filesize tag is fast, unfortunately it doesn't match the file size reported in the Finder so it's of no use for my purposes.)

I can get this much faster with the terminal command stat -f '%z' [DIR]*.[EXT], but I need it to do a recursive find within sub-folders, and with exclusions, as per the ExifTool code below. Can anyone help me write this?

In other words, is there a recursive terminal command that would return the file sizes (in bytes) and paths similar to what the ExifTool code below would return (excluding images within sub-folders containing "old" or "archive" in the folder names)?

exiftool -i HIDDEN -ext psb -ext psd -ext png -ext tif -ext jpg -MacOS:MDItemLogicalSize -filename -if5 '$directory !~ /old|archive/i' -r [DIR]

* In addition to STAT, I believe FIND could also potentially work.

Returned results would look something like this:

96012796 /Users.../A.png
796007856 /Users.../B.psd
655004788 /Users.../C.psb
865411272 /Users.../D.psd
34045280 /Users.../E.tif
Title: Re: MacOS shell command to return image sizes & paths, but excluding certain folders
Post by: Chris S on March 28, 2023, 02:39:03 AM
I believe I got what I needed thanks to some help from peeps on StackOverflow...

set searchFolder to quoted form of POSIX path of (choose folder)

set shellScript to do shell script "find " & searchFolder & " -mindepth 1 \\( -iname \"*.tif\" -or -iname \"*.png\" -or -iname \"*.psd\" -or -iname \"*.jpg\" -or -iname \"*.psb\" \\) ! \\( -ipath \"*old*\" -or -ipath \"*archive*\" -or -ipath \"*.app*\" \\) |sort -f |while read line ;do stat -f '%z  %N' \"$line\" ;done"
Title: Re: MacOS shell command to return image sizes & paths, but excluding certain folders
Post by: Chris S on March 28, 2023, 10:08:43 PM
Previous solution I posted was not correct. This new code does the trick; also added -FileOrder -Directory to the ExifTool code to match the sorting.

set searchFolder to quoted form of POSIX path of (choose folder)

set shellScript to do shell script "find " & searchFolder & ¬
    " -type d ! \\( -iname '*old*' -o -iname '*archive*' \\) |while read line ;do find \"$line\" -type f \\( -iname '*.psd' -o -iname '*.jpg' -o -iname '*.tif' -o -iname '*.psb' -o -iname '*.png' \\) -maxdepth 1 ;done |sort -f |tr -s '//' |while read line ;do stat -f '%z %N' \"$line\" ;done"

Title: Re: MacOS shell command to return image sizes & paths, but excluding certain folders
Post by: greybeard on March 29, 2023, 08:44:03 AM
The -filesize tag is fast, unfortunately it doesn't match the file size reported in the Finder so it's of no use for my purposes

What do you mean by this?

Doesn't -filesize# (or -n) show the same result as you would see in finder?
Title: Re: MacOS shell command to return image sizes & paths, but excluding certain folders
Post by: Phil Harvey on March 29, 2023, 10:30:51 AM
I get the same value even if the file has a resource fork:

> stat -f '%z %N' tmp/LayerExample2.psd
36490 tmp/LayerExample2.psd
> exiftool -filesize# -resourceforksize# tmp/LayerExample2.psd
File Size                       : 36490
Resource Fork Size              : 7028
Title: Re: MacOS shell command to return image sizes & paths, but excluding certain folders
Post by: Chris S on March 29, 2023, 11:53:04 AM
OMG... I didn't know about adding the # symbol to -filesize# to get it returned in bytes. Thank you, that gets me what I needed so much easier and better!
Title: Re: MacOS shell command to return image sizes & paths, but excluding certain folders
Post by: StarGeek on March 30, 2023, 01:55:20 PM
The # applies the -n (--printConv) option (https://exiftool.org/exiftool_pod.html#n---printConv) to individual tags rather than applying it globally.