Simon - your a gem<br><br>there was a few syntax errors in what I was doing - <br><br>here is the corrected version:<br>note the spaces between the brackets [ EXAMPLE ]<br>and &#39;test&#39; was removed as its not needed. <br>
<br>now onto my &quot;unexpected end of line&quot;<br>cheers,<br>Ben<br><br> #File Locations!<br>location_Parent=~/Documents/sight_of_sound<br>location_IMG=~/Documents/Sight_of_sound/IMG<br>location_AUD=~/Documents/Sight_of_sound/AUD<br>
<br>if  [ -d &quot;$location_Parent&quot; ]<br>then<br>echo &quot;Parent Directory OK&quot;<br>else<br>    echo &quot;Error: Parent directory does not exist. Creating directory&quot;<br>    mkdir $location_Parent<br>fi<br>
<br>if [ -d &quot;$location_IMG&quot; ]<br> then<br>    echo &quot;IMG Directory OK&quot;<br>else<br>    echo &quot;Error: IMG directory does not exist. Creating directory&quot;<br>    mkdir $location_IMG<br>fi<br><br>if [ -d &quot;&quot;$location_AUD&quot;&quot; ]<br>
then<br>    echo &quot;AUD Directory OK&quot;<br>else<br>    echo &quot;Error: AUD directory does not exist. Creating directory&quot;<br>    mkdir $location_AUD<br>fi<br><br><br><br><br><div class="gmail_quote">2009/6/14 Simon Yuill <span dir="ltr">&lt;<a href="mailto:simon@lipparosa.org">simon@lipparosa.org</a>&gt;</span><br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Hi Ben,<br>
<br>
This bit of Python will do the dame job for you, if you can use Python<br>
for your scripts:<br>
<br>
<br>
def validateFilePath(filepath, create=False, isDirectory=False):<br>
        &quot;&quot;&quot;<br>
        Converts C{filepath} to absolute form, expanding the<br>
        user if necessary,and tests if it exists.  If the<br>
        directory, or any sub-directory in the path<br>
        does not exist, can optionally create it (off by default).<br>
<br>
        Returns validated path.  If C{create} is set to false,<br>
        and the path does not exist, returns C{None}.<br>
        &quot;&quot;&quot;<br>
        absfilepath = os.path.abspath(os.path.expanduser(filepath))<br>
        if filepath[-1] == &#39;/&#39;:absfilepath = absfilepath + &#39;/&#39;<br>
        if not isDirectory:dirpath = os.path.dirname(absfilepath)<br>
        else:dirpath = absfilepath<br>
        if os.path.exists(dirpath):return absfilepath<br>
        if create:<br>
                os.makedirs(dirpath)<br>
                return absfilepath<br>
        else:return None<br>
<br>
<br>
best wishes<br>
Si<br>
<div><div></div><div class="h5"><br>
<br>
Ben Rush wrote:<br>
&gt; Im trying to check if a series of directory exists and if not create<br>
&gt; them, and am having issues. All the instances of test return with the<br>
&gt; error &quot;test: [-d: unary operator expected&quot; . Searching around I see that<br>
&gt; if the variable is in double quotes its solves the problem - but for<br>
&gt; some reason, not for me. The script still makes the directories if the<br>
&gt; don&#39;t exists, however if they DO - it still tries to create them.<br>
&gt;<br>
&gt; What noob things am I doing wrong here?<br>
&gt;<br>
&gt; This is just one small but of my puzzle - if there is anybody<br>
&gt; knowledgeable in shell scripting that could give me a few hours to in<br>
&gt; the next day or so - I&#39;d be happy to pay for your time.<br>
&gt;<br>
&gt; Cheers,<br>
&gt; Ben Rush<br>
&gt;<br>
&gt; [code]<br>
&gt; #!/bin/bash<br>
&gt; location_Parent=~/Documents/sight_of_sound<br>
&gt; location_IMG=~/Documents/Sight_of_sound/IMG<br>
&gt; location_AUD=~/Documents/Sight_of_sound/AUD<br>
&gt;<br>
&gt; if test [-d &quot;$location_Parent&quot;]<br>
&gt; then<br>
&gt; echo &quot;Parent Directory OK&quot;<br>
&gt; else<br>
&gt;     echo &quot;Error: Parent directory does not exist. Creating directory&quot;<br>
&gt;     mkdir $location_Parent<br>
&gt; fi<br>
&gt;<br>
&gt; if test [-d &quot;$location_IMG&quot;]<br>
&gt;  then<br>
&gt;     echo &quot;IMG Directory OK&quot;<br>
&gt; else<br>
&gt;     echo &quot;Error: IMG directory does not exist. Creating directory&quot;<br>
&gt;     mkdir $location_IMG<br>
&gt; fi<br>
&gt;<br>
&gt; if test [-d &quot;$location_AUD&quot;]<br>
&gt; then<br>
&gt;     echo &quot;AUD Directory OK&quot;<br>
&gt; else<br>
&gt;     echo &quot;Error: AUD directory does not exist. Creating directory&quot;<br>
&gt;     mkdir $location_AUD<br>
&gt; fi<br>
&gt; [/code]<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
</div></div>&gt; ------------------------------------------------------------------------<br>
&gt;<br>
&gt; _______________________________________________<br>
&gt; members mailing list<br>
&gt; <a href="mailto:members@electronclub.org">members@electronclub.org</a><br>
&gt; <a href="http://lists.electronclub.org/cgi-bin/mailman/listinfo/members" target="_blank">http://lists.electronclub.org/cgi-bin/mailman/listinfo/members</a><br>
&gt;<br>
&gt; Instructions for changing your mailing list settings:<br>
&gt; <a href="http://lists.electronclub.org/emailhowto.html" target="_blank">http://lists.electronclub.org/emailhowto.html</a><br>
<br>
_______________________________________________<br>
members mailing list<br>
<a href="mailto:members@electronclub.org">members@electronclub.org</a><br>
<a href="http://lists.electronclub.org/cgi-bin/mailman/listinfo/members" target="_blank">http://lists.electronclub.org/cgi-bin/mailman/listinfo/members</a><br>
<br>
Instructions for changing your mailing list settings:<br>
<a href="http://lists.electronclub.org/emailhowto.html" target="_blank">http://lists.electronclub.org/emailhowto.html</a><br>
</blockquote></div><br>