I have cobbled together a Bash script to randomoly select an image from multiple sub directories and it works well.
I now need to have two .txt files containing the image name and the directory name the image came from. The contents of the two txt files will be inserted into an article on a Joomla website.. Image source is multiple directories in: /home/my-dir/public_html/images/archive-pics/
The destination directory for random image and the two .txt files is : /home/my-dir/public_html/images/archive-pic-of-day/
The desired format in the .txt files is: " 005.jpg " in the name.txt file and " outside-buildings " in the dir.txt file ... without the quotes. The image source is ....archive-pics/outside-building/005.jpg.
Any suggestions on the code needed to create the two .txt files please when the random image is selected. I'm not a coder but I can follow instructions.
My script to select the image is:
#!/usr/bin/bash
#pic-of-day.sh: Randomly picks an image
# /bin/bash /home/my-dir/pic-of-day.sh ... for cron
# first, delete the existing image in the pic of the day folder
rm /home/my-dir/public_html/images/archive-pic-of-day/*.jpg
# now, look through the archive images and pick one to copy to the
# pic of the day folder
cp "$(find /home/my-dir/public_html/images/archive-pics/ -iname '*.jpg' \
-print0 | shuf -z -n1)" \
/home/my-dir/public_html/images/archive-pic-of-day/
Thank you for your comment @Pourko ..... perhaps I didn't explain very well ...
The image is displayed on a website page via an article container which will have an accompanying descriptive text boiler plate. Because we have multiple subdirectories containing the images, I want to insert text at an appropriate point in the boiler plate that identifies where the event had occurred. All the subdirectories are labeled as the event. A simplistic example is: blah, blah ... this project took place in the [blacksmith-shop] over several years blah, blah. The text within the [ ] would be the subdirectory name containing the image. I do not want the entire path nor do I want the file name at that point. The story itself will be either above or below the image.
To further complicate the issue, I have to use a Joomla extension to import the content into the article and the extension recognizes .txt files. That is why I thought two simple .txt files containing the data would work like a charm.
Right now, I don't need the file name but I can forsee that we may need it in the future. A new image along with a story is displayed daily. I'm sorry, but I don't see how your solution would work into my article.