Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Organising photos into a list (O/T)



Bart Schaefer wrote:
> On Mar 9, 10:15am, zzapper wrote:
> }
> } I needed to organise about 60 images into a numerical list.
> [...]
> } (Just realised, the best way would have been to print them all and then 
> } organise them on a table: but that would have taken ages)
> 
> If the file names or dates don't already reflect something close to the
> ordering you want, so you have to look at the pictures to number them,
> then no command-line tool is going to be of much help.  You might be
> able to write a function to renumber (by renaming) a bunch of files
> when you find that you need to move one of them to an earlier place in
> the list, but you still need to type out at least the names of the
> file to be moved and the file to move it "ahead" of.

Or, if this is the problem, you can reduce it to reordering a list of
file names (in an editor would be best, though you could do it
with "IFS=$'\n' vared array").

# Get the list of files as currently ordered
array1=(*)
# Output one per line to a file
print -l $array1 >file
# Edit the file.  Just reorder the lines the way you want.
vi file
# Put the ordered files into a new array
array2=(${(f)"$(<file)"})
# Sanity check
(( ${#array1} != ${#array2} )) && print 'Wrong number of files!'
# Rename files into a subdirectory, which
# prevents overwriting.  (This is paranoia if
# your are adding numbers.)
mkdir newnames
# Use 3 digit numbers (arbitrary).
integer -Z 3 i
typeset name
# For each file in the required order...
for (( i = 1; i <= ${#array2}; i++ )); do
   name=$array2[i]
   # Move into the subdirectory tagged with the new position as index.
   mv $name newnames/${i}_$name
done


-- 
Peter Stephenson <pws@xxxxxxx>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070


To access the latest news from CSR copy this link into a web browser:  http://www.csr.com/email_sig.php

To get further information regarding CSR, please visit our Investor Relations page at http://ir.csr.com/csr/about/overview



Messages sorted by: Reverse Date, Date, Thread, Author