On 01/30/2018 12:45 PM, Cameron Simpson wrote:
On 30Jan2018 12:01, Patrick O'Callaghan
<pocallaghan(a)gmail.com> wrote:
> On Tue, 2018-01-30 at 20:53 +1100, Cameron Simpson wrote:
>> cd your-staging-directory
>> n=1
>> while :
>> do
>> for f in *.jpg
>> do
>> [ -s "$f" ] || continue
>> while :
>> do
>> target=$( printf 'your-ordered-directory/%05d-%s' "$n"
"$f" )
>> [ -e "$target" ] || break
>> n=$((n+1))
>> done
>> mv "$f" "$target"
>> done
>> sleep 1
>> done
>>
>> That does a "mv", so give it a good test on copies first to avoid it
>> eating
>> your files!
>
> On second thoughts, I don't think this is going to work:
>
>> Then just drag images into the staging directory in the right order
>> and the
>> shell script will move them into the ordered directory with nice numeric
>> prefixes.
>
> Dragging the files 'in the right order' doesn't affect their names. The
> script loops over the files in lexical order, not in the order I've
> dragged them, so the final order won't change.
The idea is that the script picks up the files as fast as you drag them.
You might need to shrink the "sleep 1" to "sleep 0.1", or perhaps
better, to not sleep at all _if_ any files were run on that loop. The
sleep is there to stop your machine spinnning out when idle.
If you need this to be asynchronous, have a look at inotifywait(1) (part
of the inotify-tools RPM) and build your script using that tool. The
script then becomes event-driven rather than using polling.
Provided the files are picked up suffiently promptly, they are meant
to
each get a nice incrementing numeric prefix as you drag them, thus
ordering their names in the ordered directory.
> Sorry if I wasn't clear enough in my initial post.
I think I understood you. You seem to have missing the numeric profix in
the new names - the script _depends_ on you interactively dragging files
to the staging dir in a piecemeal fashion.
Also note Jons bug report.
Another untested version with a fix for his bug and a fix for the sleep
thing:
cd your-staging-directory
n=1
while :
do
moved=
for f in *.jpg
do
[ -s "$f" ] || continue
while :
do
target=$( printf 'your-ordered-directory/%05d-%s' "$n"
"$f" )
[ -e "$target" ] || break
n=$((n+1))
done
mv "$f" "$target"
n=$((n+1))
moved=1
done
[ $moved ] || sleep 0.1
done
See how that logic feels to you.
If you need this to be asynchronous, have a look at inotifywait(1) and
build your script according to that.
Cheers,
Cameron Simpson <cs(a)cskk.id.au> (formerly cs(a)zip.com.au)
_______________________________________________
users mailing list -- users(a)lists.fedoraproject.org
To unsubscribe send an email to users-leave(a)lists.fedoraproject.org
--
----------------------------------------------------------------------
- Rick Stevens, Systems Engineer, AllDigital ricks(a)alldigital.com -
- AIM/Skype: therps2 ICQ: 22643734 Yahoo: origrps2 -
- -
- "More hay, Trigger?" "No thanks, Roy, I'm stuffed!"
-
----------------------------------------------------------------------