Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 25 Nov 2001 19:46:17 -0700
From:      "Totally Jayyness" <Jayyness@mindspring.com>
To:        <freebsd-questions@freebsd.org>
Subject:   Scripting Problems please help
Message-ID:  <001801c17624$85c958f0$0300a8c0@jayyness.com>

index | next in thread | raw e-mail

[-- Attachment #1 --]
Sorry to bother you but I am going crazy... I am trying to write a simple script to traverse directories and create playlist files in those directories.  I have tried several things but keep getting errors.  I am obviously having issues with the spaces inside the directory names (see below for scripts I have triedand errors I am getting).  Any help you guys/gals could offer would be greatly appreciated!!!!!!  (Oh, please reply directly as I am not signed up for the mailing list, probably would be a good idea to do that though.)

OK, I have mp3 files n several directories.  Here is a sample of directories.

/usr/test
/usr/test/W
/usr/test/W/Wall of Voodoo
/usr/test/W/Wall of Voodoo/Dark Continent
/usr/test/W/Wall of Voodoo/WoV Live
/usr/test/W/Weatherman, The
/usr/test/W/Weatherman, The/Global 851
/usr/test/W/When in Rome
/usr/test/W/White Town
/usr/test/W/Wil Smith

What I woudl like to do is have a script search each of the directories for mp3 files and dump that output into a .m3u (playlist file) in it.  for example..

/usr/test/test.m3u
/usr/test/W/W.m3u
/usr/test/W/Wall of Voodoo/Wall of Voodoo.m3u
/usr/test/W/Wall of Voodoo/Dark Continent/Dark Continent.m3u
/usr/test/W/Wall of Voodoo/WoV Live/WoV Live.m3u
/usr/test/W/Weatherman, The/Weatheran, The.m3u
/usr/test/W/Weatherman, The/Global 851/Global 851.m3u
/usr/test/W/When in Rome/When in Rome.m3u
/usr/test/W/White Town/White Town.m3u
/usr/test/W/Wil Smith/Wil Smith.m3u

It is ok for parent directories to include mp3s from subdirectories... so Weatherman, The.m3u would also include the mp3s in it's subdirectory.

With help, I have been able to figure out how to get a list of the subdirectories, wrap the subdirectories in qoutes but after that is where it all falls apart.  My script seems to disregard the qoutes I put in there and sees the spaces and then fails miserably.

I haven't been able to get specifically named m3u files, but putting a songs.m3u file in each directory will work just as good.  I have tried 2 scripts so far.  One that wraps the directory in qoutes 
"/usr/test/W/Weatherman, The/Global 851/"
and one that builds the directory like Unix does when you tab out the directory:
/usr/test/W/Weatherman,\ The/Global\ 851/

SCRIPT 1
#!/bin/sh
        #
        #  Catalog MP3 files on a directory basis
        #
MP3_ROOT="/usr/test"
# Find Directories under /usr/test then wrap entire directory in qoutes to encompass spaces
for mp3_dir in `find $MP3_ROOT -type d -print | sed -e 's/^/\"/' -e 's/$/\"/'` ; do
        # Find mp3 files in individual directories, clean them up for playlist, dump to m3u file in that directory
        find $mp3_dir -iname '*.mp3' # | sed -e  's;/usr/test;http://12.159.64.5;' -e 's/ /%20/g' > $mp3_dir/songs.m3u
done

When I run this script, though, this is what I get.
-snip-
root:/usr/test>./parse
find: ./parse: cannot create "/usr/test"/songs.m3u: directory nonexistent
"/usr/test": No such file or directory
find: ./parse: cannot create "/usr/test/W"/songs.m3u: directory nonexistent
"/usr/test/W": No such file or directory
find: ./parse: cannot create "/usr/test/W/Wall/songs.m3u: directory nonexistent
"/usr/test/W/Wall: No such file or directory
-snip

SCRIPT 2
#!/bin/sh
        #
        #  Catalog MP3 files on a directory basis
        #
MP3_ROOT="/usr/test"
for mp3_dir in `find $MP3_ROOT -type d -print | sed -e 's/ /\\ /'` ; do
        find $mp3_dir -iname "*.mp3" | sed -e  's;/usr/test;http://12.159.64.5;' -e 's/ /%20/g' > $mp3_dir/songs.m3u
done

And when I run this script -snip-
find: ./parse: cannot create /usr/test/W/Wall/songs.m3u: directory nonexistent
/usr/test/W/Wall: No such file or directory
find: ./parse: cannot create of/songs.m3u: directory nonexistent
of: No such file or directory
find: ./parse: cannot create Voodoo/songs.m3u: directory nonexistent
Voodoo: No such file or directory
-snip-

[-- Attachment #2 --]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<META content="MSHTML 6.00.2600.0" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV>
<DIV><FONT face=Arial size=2>Sorry to bother you but I am going crazy... I am 
trying to write a simple script to traverse directories and create playlist 
files in those directories.&nbsp; I have tried several things but keep getting 
errors.&nbsp; I am obviously having issues with the spaces inside the directory 
names (see below for scripts I have triedand errors I am getting).&nbsp; Any 
help you guys/gals could offer would be greatly appreciated!!!!!!&nbsp; (Oh, 
please reply directly as I am not signed up for the mailing list, probably would 
be a good idea to do that though.)</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>OK, I have mp3 files n several directories.&nbsp; 
Here is a sample of directories.</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>/usr/test<BR>/usr/test/W<BR>/usr/test/W/Wall of 
Voodoo<BR>/usr/test/W/Wall of Voodoo/Dark Continent<BR>/usr/test/W/Wall of 
Voodoo/WoV Live<BR>/usr/test/W/Weatherman, The<BR>/usr/test/W/Weatherman, 
The/Global 851<BR>/usr/test/W/When in Rome<BR>/usr/test/W/White 
Town<BR>/usr/test/W/Wil Smith</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>What I woudl like to do is have a script search 
each of the directories for mp3 files and dump that output into&nbsp;a .m3u 
(playlist file) in it.&nbsp; for example..</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial 
size=2>/usr/test/test.m3u<BR>/usr/test/W/W.m3u<BR>/usr/test/W/Wall of 
Voodoo/Wall of Voodoo.m3u<BR>/usr/test/W/Wall of Voodoo/Dark Continent/Dark 
Continent.m3u<BR>/usr/test/W/Wall of Voodoo/WoV Live/WoV 
Live.m3u<BR>/usr/test/W/Weatherman, The/Weatheran, 
The.m3u<BR>/usr/test/W/Weatherman, The/Global 851/Global 
851.m3u<BR>/usr/test/W/When in Rome/When in Rome.m3u<BR>/usr/test/W/White 
Town/White Town.m3u<BR>/usr/test/W/Wil Smith/Wil Smith.m3u</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>It is ok for parent directories to include mp3s 
from subdirectories... so Weatherman, The.m3u would also include the mp3s in 
it's subdirectory.</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>With help, I have been able to figure out how to 
get a list of the subdirectories, wrap the subdirectories in qoutes but after 
that is where it all falls apart.&nbsp; My script seems to disregard the qoutes 
I put in there and sees the spaces and then fails miserably.</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>I haven't been able to get specifically named m3u 
files, but putting a songs.m3u file in each directory will work just as 
good.&nbsp; I have tried 2 scripts so far.&nbsp; One that wraps the directory in 
qoutes </FONT></DIV>
<DIV><FONT face=Arial size=2>"/usr/test/W/Weatherman, The/Global 
851/"</FONT></DIV>
<DIV><FONT face=Arial size=2>and one that builds the directory like Unix does 
when you tab out the directory:
<DIV><FONT face=Arial size=2>/usr/test/W/Weatherman,\ The/Global\ 
851/</FONT></DIV></FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>SCRIPT 1</FONT></DIV>
<DIV><FONT face=Arial 
size=2>#!/bin/sh<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
#<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #&nbsp; Catalog MP3 files on a 
directory basis<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
#<BR>MP3_ROOT="/usr/test"</FONT></DIV>
<DIV><FONT face=Arial size=2># Find Directories under /usr/test then wrap entire 
directory in qoutes to encompass spaces<BR>for mp3_dir in `find $MP3_ROOT -type 
d -print | sed -e 's/^/\"/' -e 's/$/\"/'` ; do</FONT></DIV>
<DIV><FONT face=Arial size=2>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; #&nbsp;Find 
mp3 files in individual directories, clean them up for playlist, dump to m3u 
file in that directory<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; find 
$mp3_dir -iname '*.mp3' # | sed -e&nbsp; 's;/usr/test;http://12.159.64.5;' -e 
's/ /%20/g' &gt; $mp3_dir/songs.m3u<BR>done</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>When I run this script, though, this is what I 
get.</FONT></DIV>
<DIV><FONT face=Arial size=2>-snip-</FONT></DIV>
<DIV><FONT face=Arial size=2>root:/usr/test&gt;./parse<BR>find: ./parse: cannot 
create "/usr/test"/songs.m3u: directory nonexistent<BR>"/usr/test": No such file 
or directory<BR>find: ./parse: cannot create "/usr/test/W"/songs.m3u: directory 
nonexistent<BR>"/usr/test/W": No such file or directory<BR>find: ./parse: cannot 
create "/usr/test/W/Wall/songs.m3u: directory nonexistent<BR>"/usr/test/W/Wall: 
No such file or directory</FONT></DIV>
<DIV><FONT face=Arial size=2>-snip</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>SCRIPT 2</FONT></DIV>
<DIV><FONT face=Arial 
size=2>#!/bin/sh<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
#<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #&nbsp; Catalog MP3 files on a 
directory basis<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
#<BR>MP3_ROOT="/usr/test"<BR>for mp3_dir in `find $MP3_ROOT -type d -print | sed 
-e 's/ /\\ /'` ; do<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; find $mp3_dir 
-iname "*.mp3" | sed -e&nbsp; 's;/usr/test;http://12.159.64.5;' -e 's/ /%20/g' 
&gt; $mp3_dir/songs.m3u<BR>done</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>And when I run this script -snip-</FONT></DIV>
<DIV><FONT face=Arial size=2>find: ./parse: cannot create 
/usr/test/W/Wall/songs.m3u: directory nonexistent<BR>/usr/test/W/Wall: No such 
file or directory<BR>find: ./parse: cannot create of/songs.m3u: directory 
nonexistent<BR>of: No such file or directory<BR>find: ./parse: cannot create 
Voodoo/songs.m3u: directory nonexistent<BR>Voodoo: No such file or 
directory</FONT></DIV>
<DIV><FONT face=Arial size=2>-snip-</FONT></DIV></DIV></BODY></HTML>
help

Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?001801c17624$85c958f0$0300a8c0>