Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 26 Nov 2001 14:56:01 -0500
From:      <jayyness@mindspring.com>
To:        freebsd-questions@freebsd.org
Subject:   re: Scripting Problems Please Help
Message-ID:  <Springmail.105.1006804561.0.42458100@www.springmail.com>

next in thread | raw e-mail | index | archive | help
>Let's get the problem statement straight. You have a tree of files,
>some of which are mp3's, possibly called Mp3 or MP3 or mP3.

>Do you want a playlist created in each directory containing 1) the>
>mp3s in that directory, 2) the mp3s in that directory and all
>subdirectories of it, or 3) something I've overlooked?

>In each playlist, do you want the path to the file from a) the
>directory the playlist is in, b) the top of the tree you're runnings
>this from, c) absolute or d) something I've overlooked.

Sorry if this is a Duplicate e-mail, some of my e-mails don't seem to make it to the list for some reason.  Thanks for all your help.

Ok, sorry if I am not explaining this well.  Will try to give better examples.

This is what I am looking for the script to accomplish.
1.  Place a songs.m3u file in each directory below the /mp3 root.
2.  the songs.m3u file will contain all mp3 files found in that direcotry and any subdirectories off of the current directory it is in currently.
3.  the entire path to the file needs to be preserved for each mp3 (/mp3/W/Wall of Voodoo/Dark Continent/Mexican Radio.mp3) inside the songs.m3u file

So, in the base directory, there should be a master songs.m3u that will contain every mp3 with full path to it.

- In the /mp3/A directory, there will be a songs.mp3 with all the mp3s in and under the /mp3/A directory,  and full paths from root to them under it.

/mp3/A/A-Ha/Crying in the rain.mp3
/mp3/A/Alphaville/Big in Japan.mp3
/mp3/A/Alphaville/Singles/Forever Young.mp3
/mp3/A/Anthrax/rock song.mp3

- In the /mp3/A/Aphaville directory, there will be a songs.m3u with all mp3s under it and full patsh from root to them.

/mp3/A/Alphaville/Big in Japan.mp3
/mp3/A/Alphaville/Singles/Forever Young.mp3

- Then a /mp3/A/Alphaville/Singles/songs.m3u with just the files in it's directory, since there are no subdirectories under it, with full paths to the mp3s.

/mp3/A/Alphaville/Singles/Forever Young.mp3


>>>>>>>>>>>>>>>>>>>>>>>>
1a:

find . -type d |
while read songs
  do
    playlist=$(echo "$songs.m3u" | sed 's;.*/;;')
    (cd "$songs"; ls | grep -i '.mp3$' > "$playlist")
  done

1b:

find . -type d |
while read songs
  do
    playlist=$(echo "$songs.m3u" | sed 's;.*/;;')
    find "$songs" -maxdepth 1 -iname '*.mp3' > "$songs/$playlist"
  done	

1c:

find /mp3dir -type d |
while read songs
  do
    playlist=$(echo "$songs.m3u" | sed 's;.*/;;')
    find "$songs" -maxdepth 1 -iname '*.mp3' > "$songs/$playlist"
  done	

2a:

find . -type d |
while read songs
  do
    playlist=$(echo "$songs.m3u" | sed 's;.*/;;')
    (cd "$songs"; find . -iname '.mp3$' > "$playlist")
  done

2b:

find . -type d |
while read songs
  do
    playlist=$(echo "$songs.m3u" | sed 's;.*/;;')
    find "$songs" -iname '*.mp3' > "$songs/$playlist"
  done	

2c:

find /mp3dir -type d |
while read songs
  do
    playlist=$(echo "$songs.m3u" | sed 's;.*/;;')
    find "$songs" -iname '*.mp3' > "$songs/$playlist"
  done	


ls is the wrong tool for listing filenames with the path. So the only
case it works for is when all you want is files in the current
directory with the path relative to that directory (i.e. - none). Find
always lists files with full path information. So we create playlist
by the path information off - being careful to preserve multiple
spaces in the names. To get names relative to the current directory,
you cd into that directory and run find (or ls for 1a) just putting
the output in the playlist. Whether you start the outer find with "."
or "/mp3dir" is irrelevant, because the inner find is going to start
at "." after the cd. To get paths relative to the top directory, you
run the outer find on ., the inner find on the directory name, and
redirect the output appropriately. To get full paths, do the same
except that you start the outer find with the full path. If you want
to keep find from descending into subdirectories, use "-maxdepth 1".

If you need option 3 or d, it's going to wait until after I get some
sleep.

	<mike
--
Mike Meyer <mwm@mired.org>			http://www.mired.org/home/mwm/
Q: How do you make the gods laugh?		A: Tell them your plans.

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Springmail.105.1006804561.0.42458100>