Forums
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>
<select name="select" size="15">
<% ' 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 <> "_notes\" AND fName <> "css\" AND fName <> "adminImages\" then
%>
<option value="r">
<%=fName%>
</option>
<%
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)
%>
<option value="r">
<%=fName%>
</option>
<%
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)
%>
<option value="r">
<%=fName%>
</option>
<%
fName = preserveDir
next
%>
<%
fName = CStr(subFolder.name & "\"
next
%>
<%
end if
fName = ""
next
%>
</select>
</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