begin  quoting Karl Cunningham as of Sat, Mar 04, 2006 at 10:40:29AM -0800:
> I'm trying to write a bash script to distribute some music files from 
> one directory to various subdirectories based a correlation between the 
> file and directory names.  The files are mp3s and almost all contain 
> spaces in the filenames.  The filenames are of the form:
> 
> artist - title.mp3
> 
> The directories are named to correspond to the artist names.  For each 
> directory found the script should move all mp3 files that start with the 
> same text as the directory name into the corresponding directory.  For 
> instance, a file named 'Bob Dylan - Subterranean Homesick Blues.mp3' 
> should get moved into the './Bob Dylan' directory.  I tried the 
> following but everything winds up in the root directory.  Any help is 
> appreciated.
> 
> # Get the list of directories
> find . -maxdepth 1 -type d | sed -e 's/^\.\/*//' | while read dirname

you might have better luck with:

sed -e'/^\.$/d' -e's:^\./::'

> do
>  # Move any matching files into the directory
>  find . -iname "${dirname}*.mp3" -type f -maxdepth 1 -exec mv "{}" 
> "${dirname}/" \;
> done

The second use of find may be overkill.  So long as you don't have any
directories with a suffix of .mp3, "mv ${dirname}*.mp3 ${dirname}/"
should do the same trick.

-- 
_ |\_
 \|


-- 
[email protected]
http://www.kernel-panic.org/cgi-bin/mailman/listinfo/kplug-list

Reply via email to