- My solution to this chapter's challenge
relies upon the ExifTool by Phil Harvey.
You can obtain ExifTool from Phil Harvey's website
as shown on the screen.
The program Pic n Sort calls this tool
to examine found jpeg files
as it recursively scans the name directory
and all sub-directories.
If the ExifTool isn't installed
then the program dies and displays
an appropriate error message.
Here I'm scanning the current directory tree.
Jpeg files with image caption or description data
are displayed.
The results are listed alphabetically by caption.
Only jpeg files with that information are displayed
in this list.
Files without any caption or description are skipped.
The assignment called for organizing the images
in a directory structure based on the first letter
of the caption.
I could do that in the code,
but if you're using C and you're running the program
in a terminal, you probably want a bit more control.
So I opted for specially formatted output
instead of having the program copy or move the files.
If you want to copy the files
to an organized directory structure,
specify the copy switch.
The program's output is changed
to reflect a script that would copy the files.
A variable inside the header file determines
whether the script is output for UNIX or DOS.
But the results are the same.
A sorted images directory is created.
Sub-directories, given the image captions first letter,
are also created with image files copied
to that location and renamed with the caption.
When the move switch is specified
the script generated uses move commands
instead of copy.
I recommend in UNIX that you not source the output.
That might create unpredictable results,
especially if you have spaces in your path names.
Instead, redirect the program's output to a file.
Set the file's executable bit,
then run the file to copy or move the images
to an organized directory structure.
Here you see the sorted images folder
created by running the script.
Its sub-directories are named by using
the first letter of the various image captions.
And within each folder,
you find the images copied
in this case, and renamed by using
the image caption date.
One additional command line option is available, help,
which documents the program's features.