From owner-freebsd-questions Tue Nov 27 0: 5: 5 2001 Delivered-To: freebsd-questions@freebsd.org Received: from tisch.mail.mindspring.net (tisch.mail.mindspring.net [207.69.200.157]) by hub.freebsd.org (Postfix) with ESMTP id 22BE737B405 for ; Tue, 27 Nov 2001 00:04:58 -0800 (PST) Received: from smui02.slb.mindspring.net ([199.174.114.25]) by tisch.mail.mindspring.net with esmtp (Exim 3.33 #1) id 168VL4-00042D-00; Mon, 26 Nov 2001 18:39:02 -0500 Received: by smui02.slb.mindspring.net id NAA0000009301; Mon, 26 Nov 2001 13:55:51 -0500 (EST) Date: Mon, 26 Nov 2001 13:55:51 -0500 From: To: Mike Meyer Cc: Totally Jayyness , questions@freebsd.org Subject: Re: Re: Scripting Problems please help Message-ID: X-Originating-IP: 63.228.157.5 Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG FROM: Mike MeyerDATE: 11/26/2001 08:58:18SUBJECT: RE: Scripting Problems please help Totally Jayyness <> types: >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? Ok, first off, I REALLY appreciate the help. And sorry if I am not explaining myself well. >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. This is what I am looking for... using a small portion of my test directory, we have (making the songs up, since I am work and don't have access to my box at the moment): /usr/test /usr/test/W /usr/test/W/Wall of Voodoo/mexican radio.mp3 /usr/test/W/Wall of Voodoo/another song.mp3 /usr/test/W/Wall of Voodoo/third song.mp3 /usr/test/W/Wall of Voodoo/Dark Continent/dark continent.mp3 /usr/test/W/Wall of Voodoo/Dark Continent/light continent.mp3 /usr/test/W/Wall of Voodoo/Dark Continent/grey continent.mp3 /usr/test/W/Wall of Voodoo/WoV Live/mexican radio.mp3 /usr/test/W/Wall of Voodoo/WoV Live/lola.mp3 /usr/test/W/Wall of Voodoo/WoV Live/freddie.mp3 The output I am looking for is: /usr/test/songs.m3u /usr/test/W/songs.m3u /usr/test/W/Wall of Voodoo/songs.m3u /usr/test/W/Wall of Voodoo/Dark Continent/songs.m3u /usr/test/W/Wall of Voodoo/WoV Live/songs.m3u The contentents of /usr/test/songs.m3u would contain all mp3s found in subdirectories below it. /usr/test/W/songs.m3u would contain all songs in subdirectories under /W. /usr/test/W/Wall of Voodo/songs.m3u would contain all songs in subdirectories under it, etc. For this example, the output of all 3 files would be exactly the same though, since I didn't include other letters (X,Y,Z) or other bands (Who, The). /usr/test/W/Wall of Voodoo/mexican radio.mp3 /usr/test/W/Wall of Voodoo/another song.mp3 /usr/test/W/Wall of Voodoo/third song.mp3 /usr/test/W/Wall of Voodoo/Dark Continent/dark continent.mp3 /usr/test/W/Wall of Voodoo/Dark Continent/light continent.mp3 /usr/test/W/Wall of Voodoo/Dark Continent/grey continent.mp3 /usr/test/W/Wall of Voodoo/WoV Live/mexican radio.mp3 /usr/test/W/Wall of Voodoo/WoV Live/lola.mp3 /usr/test/W/Wall of Voodoo/WoV Live/freddie.mp3 The contentents of /usr/test/W/Wall of Voodoo/Dark Continent/songs.m3u would be: /usr/test/W/Wall of Voodoo/Dark Continent/dark continent.mp3 /usr/test/W/Wall of Voodoo/Dark Continent/light continent.mp3 /usr/test/W/Wall of Voodoo/Dark Continent/grey continent.mp3 I actually eventually have to turn all the ' ' (spaces) into '%20' but I think that will be simple versus getting the songs.m3u files built. From you example below, it looks like it might be possible to have the songs.m3u file actually be named after the last directory (W.m3u, Wall of Voodoo.m3u, Dark Continent.m3u) by probably using a command similar to -maxdepth flag, but songs.m3u is more than fine... I can find how to do that later. >>>>>>>>>>>>>>>>>>>>>>>>>>>> 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.