Triggering off the gap in modification times is a good idea, and I cannot find that function in any standard folder splitting program.
So, here is a script to move photos into new folders via detecting 30 second gap between batches. I'll let you wrestle with the "watchfolder" aspect yourself.
This bash script works OK on Windows+cygwin and on CentoOS Linux. It also runs OK on macOS, with one small change described below. I do not have a Debian to test.
Note that the script as written here has a symbol "echocmd" that is set so as to
show the mkdir and mv commands that
will be executed when the script is tweaked to actually do its job. You'll have to de-comment one line of the script, defining "echocmd=" to get the commands executed instead of shown. I've done this as a defensive programming technique. My experience is that shell scripts are easily disrupted by slight differences between systems, so it's a good idea to run them in some sort of nondestructive simulation mode before turning them loose to change files.
Code: Select all
#!/bin/bash
# Split all *.jpg files in current folder into subfolders,
# each subfolder containing no more than specified number of files,
# with no longer than specified seconds between successive files.
# Each subfolder is named as the first file that it contains, with "_dir" added.
MAXFILESPERBATCH=100
MAXSECONDSBETWEENFILES=20
## Initialize $echocmd so as to show what the script will do when run.
echocmd=echo
## If the following line is commented, then mkdir and mv commands will be shown rather than executed.
## You should check the script behavior, before un-commenting this line to actually do the work.
##echocmd=
lastmtime=0
numfilesinbatch=0
while IFS= read -r fname
do
if [ -f "$fname" ]; then
mtime=`stat --format=%Y "$fname"`
if [ $(( mtime - lastmtime )) -gt $MAXSECONDSBETWEENFILES -o $numfilesinbatch -ge $MAXFILESPERBATCH ]; then
dirname="${fname%.*}"_dir
$echocmd mkdir "$dirname"
numfilesinbatch=0
fi
lastmtime=$mtime
$echocmd mv "$fname" "$dirname"
numfilesinbatch=$(( numfilesinbatch + 1 ))
fi
done < <(ls -1tr *.jpg)
Note that the file extension ".jpg" is specified in the ls command at the bottom of the script. The extension will probably be case sensitive, so you may need to change that to be ".JPG" (or whatever other extension you want to target).
For macOS, the format argument of the stat command must be modified as follows:
Note also that the default shell for macOS is now zsh, not bash, and this script is not compatible with zsh. If you want to run it interactively, get yourself into a bash shell first.
If you have any trouble, I suggest to start by contacting me by email,
support@zerenesystems.com . Then we can clean this thread up after the problem is fixed.
--Rik