Determining the presence  of a file with JavaScript?
<p>I have folder/file tree generated by JavaScript where the folder and files each have checkbox inputs with paths associated with them, like:</p>

<pre><code>/var/www/site/user/folder7/ or
/var/www/site/user/folder7/file.txt or
/var/www/site/user/folder7/file.? (? being any file extension)
</code></pre>

<p>In the case of these paths I need only</p>

<pre><code>/var/www/site/user/folder7
</code></pre>

<p>I know that normally to remove file names one would use something like:</p>

<pre><code>var full_path = node.context.nextElementSibling.value;
var folder_target_path = full_path.substring(0, full_path.lastIndexOf("/"));
</code></pre>

<p>However this return either:</p>

<pre><code>/var/www/site/user/folder7 or
/var/www/site/user
</code></pre>

<p>I could use the lastIndexOf() method if I could use some regex to find .? and then up to the last '/'; however I am fairly new to javascript and have never used regex in it. </p>

<p>Could you suggest an effecient way to get only the folder and not the file path in all cases?</p>

<p>Regards,
Steve</p>
