[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: OT: scripting question

Stephen Gran wrote:
> Hello all,
> What I'd like to end up with is a short script that will scan my music
> directories and output to a file.  I'd like this to strip off the full
> path and any ending extension, and ideally leave a blany\k line in
> between directories.  The best I can do so far is :
> ls -R /home/mp3 | (read filename; while [ ! -z "$filename" ]; do echo "${filename//mp3/ }" >> mp3.list; read filename; done)
> This strips the extensions (almost all mp3's - built up from before I
> found out about Ogg Vorbis), but I'm left with the full path and no
> blank line between directories.  I seem to think the blank line could be
> inserted by a "if filename is a directory, then echo "$filename" >>
> mp3.list followed by \n", but I can't quite work out how to do it.  man
> bash is giving me a headache, and I thought I'd turn to you guys and
> gals.
> Any thoughts?

How about this?

for dir in `find $DIR -type d | sort`
        echo $dir
        for file in `find $dir -maxdepth 1 -type f | sort`
                printf "\t"
                echo $file | sed 's!^.*/!!' | sed 's!\..*$!!'
exit 0

What do you think?


Best Regards,

mds resource

Dare to fix things before they break . . .

Our capacity for understanding is inversely proportional to how much we
think we know.  The more I know, the more I know I don't know . . .

Reply to: