Summary
I have thousands of pictures that were titled in full sentences. I am trying to automate a way to do clean them up with a single script, and then reuse that script as I add more pictures.
The general idea is to find the pictures that are malformed, then process them through a set of renames and formatting.
So far, I've used tools like 'find' and 'SED' and 'Rename' and even tried 'mv' and such....
Needs
Remove words like in, an, the, on, etc. and commas, underscores, etc.
Rename the first word in the file to the parent directory name as
(Parent Directory) [filename nouns verbs tags].jpg.Title Case Every Word That Is Left.
Run this against a folder and it's sub-folders.
Remove duplicate words
Create the format of "(Parent Folder) [Tag Tag Tag Tag Tag].ext"
example: "/path/to/my/files/travel/Denver/(Denver) [July 2019 Sarah Saw Blue Bear].jpg"
Example Process:
- Find any files that do not start with "("
(eliminating some search folders and special files that shouldn't be touched)
find /path/to/my/files/travel -not -path '*/\.*' -not -path "*Unsorted*" -not -path "*Tools*" -not -path "*Searches*" -type f \( -not -iname '(*' -not -iname '_*' -not -iname 'Icon*' -not -iname '∆*' \)
Results of the find
- "/path/to/my/files/travel/Denver/My trip to Denver on July 2019 with Sarah and saw the blue bear.jpg"
- "/path/to/my/files/travel/Tampa/Tampa Trip for work, 2018.png"
. . . . and about 36000 other photos that I haven't iterated through.
Pass those found files to a renamer, like SED or Rename? http://plasmasturm.org/code/rename
rename -v --camelcase -X --trim --subst-all word1 word2 {filename}
I suspect rename is just a wrapper for SED, but.. whatever worksIterate through all the potential renames that will need to be made, without replacing fractions of the word.
for example, replacing "the" with "" should not trim "These" into "se"
Original Replacement
"The" ""
"In" ""
"Jul " "July"
"Colo Springs" "Colorado Springs"
"Daughter" "Sarah Jones"
" " " "
<-- Double space to single space
"," " "
<-- Replace commas with spaces, etc.
- Correct duplications.
In the Example for Tampa, simply adding (Tampa) to the name would result in "(Tampa) Tampa Trip Work 2018.png"
Result
When complete, the whole process would have renamed our example files:
"/path/to/my/files/travel/Denver/My trip to Denver on July 2019 with Sarah and saw the blue bear.jpg"
becomes"/path/to/my/files/travel/Denver/(Denver) July 2019 Sarah Saw Blue Bear.jpg"
and"/path/to/my/files/travel/Tampa/Tampa Trip for work, 2018.png"
becomes"/path/to/my/files/travel/Tampa/(Tampa) Trip Work 2018.png"
Missing Piece(s):
- I don't know how to pass a set of replacement words per file and iterate each file found in the find process
- I don't know how to capture the parent directory name for the file
- I am not sure how to eliminate duplicates
Am I even going down the right path here?
Any help would be appreciated.
Update
I was able to find this
https://stackoverflow.com/a/49778528/688243
So I applied it to my 'find' - so part of the puzzle is done - I have figured out how to find the files I need to correct.
I think the next step would be to iterate 'rename' or 'SED' through each file, by replacing the 'echo'....
IFS=$'\n'
for i in $(find /path/to/my/files/travel -not -path '*/\.*' -not -path "*Unsorted*" -not -path "*Tools*" -not -path "*Searches*" -type f \( -not -iname '(*' -not -iname '_*' -not -iname 'Icon*' -not -iname '∆*' \) );
do
echo "$i"
done
unset IFS
echo mv
until you're happy)), feed it withfind . -type f -print0 | xargs -0 -r yourscript
. Readman bash find xargs
.