MacOS shell command to return image sizes & paths, but excluding certain folders

Started by Chris S, March 27, 2023, 11:27:25 PM

Previous topic - Next topic

Chris S

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

Chris S

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"

Chris S

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"


greybeard

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?

Phil Harvey

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
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

Chris S

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!

StarGeek

"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype