----- Original Message ----- From: "Istvan Gabor" <suseuser04@freemail.hu> To: <opensuse@opensuse.org> Sent: Friday, November 14, 2008 5:30 AM Subject: Re: [opensuse] forcing order of file copy Jos van Kan <vankan@kabelfoon.nl> írta:
You can check for yourself that this gets them in alphabetical order by:
for file in *mp3; do echo $file; done
Regards,
Jos van Kan registered Linux user #152704
Thanks Jos. In the meantime I found a program called FATSort Utility which does exactly what I need. It can be found at: http://fatsort.berlios.de/ The only drawback is you have to run it as root since it operates with the unmounted flash card directly. Regarding the solution you gave: it works with one directory at a time. What is if you have several directories and don't want to create and fill them individually? --------- kinda kludgy what with needing to write a little script and having to cd to a particular spot to work from and all, but... Well, your need is weird, so of course no tools have nice options built in for that to make nice elegant solution, so we have to brute force it. # Step 1: create a small script that takes a single argument # and copies that file to the usb drive, preserving relative paths vi ~/bin/mycpy: ----top---- #!/bin/sh # usb stick mount point # USB=/media/VOLUME etc... USB=/mnt/sdb R="${1#*/}" mkdir -p "${USB}/${R%/*}" >/dev/null 2>&1 cp -f "$R" "${USB}/${R##*/}" ---end--- # Now make the script executable chmod 755 ~/bin/mycpy # Above you just do one time. From now on you do this to run: # cd to the top level where your mp3's are cd /shared/tunes # use find to generate a file listing # use sort to sort # use xargs to perform an action (mycpy) once for each file. # use null-terminate option for all 3 utils to handle filenames robustly find ./ ! -type d -print0 |sort -z |xargs -0rn 1 mycpy That find syntax will find all files that aren't directories because most of my tunes are .ogg and many are .wma and only some are .mp3 Also I don't want to have to care about up/low/mixed case. Also my player can actually use the folder.jpg's You could instead collect just mp3's this way: find ./ -name '*.mp3' -print0 |sort -z |xargs -0rn 1 mycpy Don't copy these command visually, use cut & paste. single-forward-quote is different from backtick and double-quote, and zero is different from oh. So, I said it was kludgy, but even so, here are the advantages: * There is no globbing used anywhere (even '*.mp3' isn't globbing, as it's in single-quotes, so it's merely a pattern match expression that find will use, not something the shell will try to expand into some huge list. This means that this does not care how many files you have, nor how many directories. * Correctly handles most files that have "bad" characters. spaces and most other characters are ok, not sure about double-quotes. mycpy will generate commands like this as it runs: [...] mkdir -p "/mnt/sdb/Anderson, Bruford, Wakeman, Howe/Anderson, Bruford, Wakeman, Howe" >/dev/null 2>&1 cp -f "Anderson, Bruford, Wakeman, Howe/Anderson, Bruford, Wakeman, Howe/08 - Order Of The Universe (i. Order Theme, ii. Rock Gives Courage, iii. It's So Hard To Grow, iv. The Universe).ogg" "/mnt/sdb/08 - Order Of The Universe (i. Order Theme, ii. Rock Gives Courage, iii. It's So Hard To Grow, iv. The Universe).ogg" mkdir -p "/mnt/sdb/Anderson, Bruford, Wakeman, Howe/Anderson, Bruford, Wakeman, Howe" >/dev/null 2>&1 cp -f "Anderson, Bruford, Wakeman, Howe/Anderson, Bruford, Wakeman, Howe/09 - Let's Pretend.ogg" "/mnt/sdb/09 - Let's Pretend.ogg" mkdir -p "/mnt/sdb/Anderson, Bruford, Wakeman, Howe/Anderson, Bruford, Wakeman, Howe" >/dev/null 2>&1 cp -f "Anderson, Bruford, Wakeman, Howe/Anderson, Bruford, Wakeman, Howe/folder.jpg" "/mnt/sdb/folder.jpg" mkdir -p "/mnt/sdb/Apocalyptica/Amplified A Decade of Reinventing the Cello (disc 1)" >/dev/null 2>&1 cp -f "Apocalyptica/Amplified A Decade of Reinventing the Cello (disc 1)/01. Enter Sandman.ogg" "/mnt/sdb/01. Enter Sandman.ogg" mkdir -p "/mnt/sdb/Apocalyptica/Amplified A Decade of Reinventing the Cello (disc 1)" >/dev/null 2>&1 cp -f "Apocalyptica/Amplified A Decade of Reinventing the Cello (disc 1)/02. Harmageddon.ogg" "/mnt/sdb/02. Harmageddon.ogg" [...] Ridiculously long lines intentionally left unwrapped, since the point is to try to show exactly what the script will do. In this case the single quotes in "It's So Hard To Grow" and "Let's Pretend" would be handled just fine , as well as all that other garbage. We are ignoring the messages from mkdir because most of the time it will spew a "already exists" error message which we don't care about. -- Brian K. White brian@aljex.com http://www.myspace.com/KEYofR +++++[>+++[>+++++>+++++++<<-]<-]>>+.>.+++++.+++++++.-.[>+<---]>++. filePro BBx Linux SCO FreeBSD #callahans Satriani Filk! -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org