Forums

ASP

This topic is locked

Server.MapPath error - using FileSystemObject

Posted 16 Jan 2003 10:44:48
1
has voted
16 Jan 2003 10:44:48 Josh Cooper posted:
I'm trying to create a menu list containing .. well, a list .. of Directory contents.

For example, I check the folder names of a base folder, and check the folder names of THOSE folders, and those sub folders, and so on.

Here's the mess I'm using for code:

<pre id=code><font face=courier size=2 id=code>
&lt;select name="select" size="15"&gt;
&lt;% ' make this puppy go 4 levels deep
fName = ""

Set dirObj = Server.CreateObject("Scripting.FileSystemObject"
Set dirList = dirObj.GetFolder(Server.MapPath(".")

'i = 0
for each subFolder in dirList.subFolders
fName = CStr(subFolder.name & "\"
if (fName &lt;&gt; "_notes\" AND fName &lt;&gt; "css\" AND fName &lt;&gt; "adminImages\" then

%&gt;
&lt;option value="r"&gt;
&lt;%=fName%&gt;
&lt;/option&gt;


&lt;%
Set subDirObj = Server.CreateObject("Scripting.FileSystemObject"
Set subDirList = subDirObj.GetFolder(Server.MapPath(CStr(subFolder.name)))

for each folder in subDirList.subFolders
fName = CStr(fName & folder.name)
%&gt;
&lt;option value="r"&gt;
&lt;%=fName%&gt;
&lt;/option&gt;
&lt;%
testPathName = CStr(subFolder.name & Chr(92) & folder.name)
'response.write("THIS IS MINE: " & testPathName)
Set subSubDirObj = Server.CreateObject("Scripting.FileSystemObject"
Set subSubDirList = subSubDirObj.GetFolder( Server.MapPath(testPathName) )

for each subSubFolder in subSubDirList.subFolders
preserveDir = fName
fName = CStr(fName & subSubFolder.name)
%&gt;
&lt;option value="r"&gt;
&lt;%=fName%&gt;
&lt;/option&gt;
&lt;%
fName = preserveDir
next
%&gt;

&lt;%
fName = CStr(subFolder.name & "\"
next
%&gt;

&lt;%
end if
fName = ""
next
%&gt;

&lt;/select&gt;
</font id=code></pre id=code>


I get the following error message:

<i>Error Type:
Server.MapPath(), ASP 0173 (0x80004005)
An invalid character was specified in the Path parameter for the MapPath method.</i>

I know the problem lies within my 3rd nested Server.Mappath method, because my <i>testPathName</i> variable contains a backslash "\". But, if I hard-code the string, it works fine.

Is there any way to use Server.MapPath without hard-coding the value? (You can see it works fine in the first two loops--because there's no backslash...)

Any help would be appreciated!

Thanx

Edited by - Silix on 16 Jan 2003 10:46:41

Reply to this topic