Selective and Recursive File Copy

Started by JohnF, December 04, 2023, 03:05:00 PM

Previous topic - Next topic

JohnF

#15
Hello Phil and StarGeek,

Once again - your suggestions got me the answers needed. 

The syntax to recursively find, sort and list unique subject entries in Windows is

exiftool -r DIR -subject -b -sep "\n" -sep "\n" | sort /unique > out.txt

Because of the piping this creates, I'm required to execute cmd from my calling program and pass the run string

/c exiftool -r DIR -subject -b -sep "\n" -sep "\n" | sort /unique > out.txt

I also ensure that calling program statement is set to wait for execution to complete.  Then I launch notepad, specifying to load out.txt.

Attached is a screenshot of the final program which allows me to search and copy all specified images. 

Phil Harvey

...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 ($).

JohnF

#17
Hello Phil and StarGeek,

With good success in creating the search and copy program in Windows, I'm now working to get achieve the same on macOS (10.13.6 - High Sierra).  I'm currently working from the Terminal window and using this command syntax

exiftool -r "/Volumes/Data/NBF_Photo_Library/" –if "$Keywords=~/John/" –o "/Volumes/Data/2-Star"

In the Terminal window you can see that each image is read, so the first portion of the command is working well.  The problem is that no files are written to the output directory.  I also noticed at the end of the processing I get the following which seems to indicate that each entry beyond the source directory is also treated as a source file. Any suggestions?

Thanks,
John

Error: File not found - –if
Error: File not found -  >= 0
Error: File not found - –o
  263 directories scanned
3507 image files read
    3 files could not be read

Phil Harvey

You need to use the standard hyphen (not some probably-pasted special hyphen-looking Unicode character).

Also, read my signature.

- Phil
...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 ($).

JohnF

yes, I just noticed the single quote comment. I'll but both together and give it a whirl.

JohnF

Ah... I should NEVER try to compose the command line string in WORD which leads to non-standard characters. And, of course, if I could only read just a bit further and pick up on footer, then things would go much smoother.

I'm up and running now!

JohnF

#21
Hi Phil and StarGeek,

Now that I can at least get a command to run in Terminal, I've returned to calling it programmatically.

I have two cases where I call exiftool.  Below are the code snippets for the Windows implementation, which work as expected. 

The first case (creating a comprehensive list of keywords) includes sorting, reducing the list to unique entries, and outputting to a file.  Because this is piped it required that I execute it by first calling "cmd /c".  Here's the working Windows code.

  Workingdirectory$=""
  Commandline$ = " /c exiftool -r " + Chr(34) + Input_Directory$ + Chr(34) + " -Keywords -b -sep " + Chr(34) + "\n" + Chr(34) + " -sep " + Chr(34) + "\n" + Chr(34) + " | sort /unique > " + Chr(34) + Output_Directory$ + "Keyword Listing.txt" + Chr(34)
  Result = RunProgram("cmd",Commandline$,Workingdirectory$,#PB_Program_Hide|#PB_Program_Wait)

The second case (selectively copying images to an output folder) was achieved by invoking exiftool directly. Here's the working Windows code:

  Exiftool$ = "exiftool"
  Workingdirectory$=""
  Commandline$ = " -r " + Chr(34) + Input_Directory$ + Chr(34) + " -if " + Chr(34) + "$rating >="+Rating$ + Keyword_Filter$ + Chr(34) + " -o " + Chr(34) + Output_Directory$ + Output_String$ + Chr(34)
  Result=RunProgram(Exiftool$,Commandline$,Workingdirectory$,#PB_Program_Hide | #PB_Program_Wait)

Both work just as they should in Windows.

So I'm 100% new to the mac world.  I've scoured the internet, looking also for python equivalent examples, etc. and seen some posts on this site too.  I've believe I've accounted for special characters and have substituted with Char(39) to use a single quote where needed (though not reflected in the original working Windows posted above).  It seems that my difficulties are more fundamental and that exiftool is never really even called.  I've experimented with using either "open", "sh" or "bash" in the same fashion as "cmd /c" but as of yet, no luck.  As mentioned in my previous post, when directly entering a good command string in to a Terminal window, things are good.

On the Mac, how do I call exiftool with all the associated syntax for these two cases - one to mimic using "cmd /c" as the principle program called with exiftool and its syntax passed as the argument and the other to call exiftool and its argument directly?  As you can see my calling program (PureBasic) is flexible - it allows me to specify the command, command line string, and working directory. In addition, I can stipulate if I wish to have it execute hidden, to hold execution, etc..

An answer to either would be great, both would be fantastic.  Do you have a tutorial on this?

Many, many thanks!
John

Phil Harvey

Hi John,

On Mac, your command should probably start with this to run exiftool:

/usr/local/bin/exiftool ...

Because the PATH may not include /usr/local/bin in whatever environment is used when you execute a command from PureBasic.  If this doesn't work, you could resort to:

/usr/bin/perl /usr/local/bin/exiftool ...

But this shouldn't be necessary.

- Phil
...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 ($).

JohnF

Hi Phil,

I've added the path so that I'm now calling /usr/local/bin/exiftool.  (I've also checked that exiftool can be found there - and it is).  Regrettably, this does not solve seem to work either.

I've also reached out to the PureBasic community to see what I can learn there.

It seems that Mac world has additional complexity.  I'm guessing it's just a matter of finding the right calling approach and syntax - but getting there is not intuitive.

What I can say, is that adding GUI wrapper, as I've now nicely achieved in Windows, means I can now post my 3500 image library for my extended family, and they can search for exactly the pictures they want to see, all thanks to exiftool, without every having to worry about syntax and command line operation.  The problem is our extended family is divided between Windows and Mac, so I'm trying to address both.

I would think that there are many exiftool users that would put GUI wrappers in place - which would mean easy access to examples as to how this can be accomplished.  It would be a good area to add to the forum.

Any additional thoughts would be appreciated!

Best,
John

Phil Harvey

Hi John,

I doubt this is an ExifTool-specific problem.  I think you need to figure out how to execute any command-line utility on a Mac from PureBasic.  Your post to the PureBasic community is the way to go.

There are many programming resources linked from the ExifTool home page, but nothing specific to PureBasic.

- Phil
...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 ($).

JohnF

Hi Phil,

I'm in full agreement.  Last night I created my own little command-line program which pops up a GUI and displays the command-line arguments passed to it.  With this I began to test PureBasic's actually support for calling any external .exe.  What I found is just what you've suggested - the problems I'm running in to are do to defects in PureBasic..  I'll be reaching back to their develop team with a bug/enhancement report. 

I'm delighted that I have things working well in the Windows world, and hopefully in the future this will be true for MacOS as well.

As a follow-up I plan to put a set of "How-To" notes together that I believe would be a help to others who wish  to create a simple GUI to invoke Exiftool.  I'll pass it on to you.  It's the least I can do as thanks for your support and quick replies!

Best,
John

PS.  Your tip that the full path is required to execute any .exe in MacOS gave me an important key towards meaningful troubleshooting on the Mac side. Thanks!