i am trying to write some code that will show all files within a list of directories i give it. the list is supposed to go through each directory and create names for each item which it does. I want to add in code that enables me to click on each item and it shows a select box for each. please have a look at the code below and see where i am going wrong. The select box appears for the first directory but not the second i am sure this is a quick fix but i cant see it! Thanks <%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>ASP Directory Listing Demo</title> <meta http-equiv="Content-Type" content="text/html;charset=utf-8" /> <link rel="stylesheet" type="text/css" href="jstree/mktree.css"> <script type="text/javascript" src="jstree/mktree.js"></script> </head> <body> </div> <!-- List these three folders. --> <ul class="mktree" id="tree1"> <% dim counter, counterDropDown counter = 1 bigCounter = 1 ListFolderContents(Server.MapPath("/site/druva/paul")) ListFolderContents(Server.MapPath("/site/druva/pontus")) ListFolderContents(Server.MapPath("/site/druva/sem")) %> </ul> </body> </html> <% sub ListFolderContents(path) dim fs, folder, file, item, url set fs = CreateObject("Scripting.FileSystemObject") set folder = fs.GetFolder(path) 'Display the target folder and info. Response.Write("<li class=""liOpen""><b>" & folder.Name & "</b> " ) Response.Write("<ul>" & vbCrLf) 'Display a list of sub folders. for each item in folder.SubFolders ListFolderContents(item.Path) next 'Display a list of files. for each item in folder.Files url = MapURL(item.path) if counter = 1 then arraySection = "'" & bigCounter& "'" else arraySection = arraySection & ", '" & bigCounter & "'" end if %> <li><a href="#" onclick="return display_select('<%=bigCounter %>');"><%=item.Name %></a> <span id="<%=bigCounter%>" style="display: none;"> <select name="pageOption" style="margin-top:0px; padding:0px;"> <option value="edit">Edit page <%=item.Name%></option> <option value="add">Add Page Below</option> <option value="addfolder">Create New Folder</option> </select> <input type="hidden" value="<%=item.Name%>" name="pageID" /> <input type="hidden" value="<%=item.Name%>" name="sectionID" /> <input type="submit" value="GO!" /> </span> </li> <% counter = counter+1 bigCounter = bigCounter + 1 %> <% next %> <script type="text/javascript"> <!-- function display_select(id) { var objects = new Array(<%=arraySection%>); for (var i in objects) { var element = document.getElementById(objects[i]); element.style.display = element.id == id ? 'inline' : 'none'; } return false; } //--> </script> <% Response.Write(arraySection) Response.Write("</ul>" & vbCrLf) Response.Write("</li>" & vbCrLf) %> <% end sub function MapURL(path) dim rootPath, url 'Convert a physical file path to a URL for hypertext links. rootPath = Server.MapPath("/") url = Right(path, Len(path) - Len(rootPath)) MapURL = Replace(url, "\", "/") end function %> Code (markup):
please define error that get......i have run ur code but its giving me error on MapURL fuction Invalid procedure call or argument: 'Right'. Tell me ur Erro so that i can help u..
Sorry for little late. But i have run it successfully. Looks the below code: You have take items instead of item.It may create problem b'caz inbuilt keyword... <%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>ASP Directory Listing Demo</title> <meta http-equiv="Content-Type" content="text/html;charset=utf-8" /> <link rel="stylesheet" type="text/css" href="jstree/mktree.css"> <script type="text/javascript" src="jstree/mktree.js"></script> <script type="text/javascript"> <!-- function display_select(id) { var objects = new Array(<%=arraySection%>); for (var i in objects) { var element = document.getElementById(objects[i]); element.style.display = element.id == id ? 'inline' : 'none'; } return false; } //--> </script> </head> <body> <!-- List these three folders. --> <ul class="mktree" id="tree1"> <% dim counter, counterDropDown counter = 1 bigCounter = 1 ListFolderContents("D:\projects\") 'ListFolderContents("C:\auction\druva\part2\") 'ListFolderContents("C:\auction\druva\part3\") %> </ul> <% sub ListFolderContents(path) dim fs, fo , File, items, url set fs = CreateObject("Scripting.FileSystemObject") set fo = fs.GetFolder(path) 'Display the target folder and info. Response.Write("<li class=""liOpen""><b>" & fo.Name & "</b> " ) Response.Write("<ul>" & vbCrLf) 'Display a list of sub folders. for each items in fo.SubFolders Response.write items.Path & "<br />" 'ListFolderContents(items.Path) next 'Display a list of files. for each items in fo.Files 'url = MapURL(items.path) if counter = 1 then arraySection = "'" & bigCounter& "'" else arraySection = arraySection & ", '" & bigCounter & "'" end if %> <li><a href="#" onclick="return display_select('<%=bigCounter %>');"><%=items.Name %></a> <span id="<%=bigCounter%>" style="display: none;"> <select name="pageOption" style="margin-top:0px; padding:0px;"> <option value="edit">Edit page <%=items.Name%></option> <option value="add">Add Page Below</option> <option value="addfolder">Create New Folder</option> </select> <input type="hidden" value="<%=items.Name%>" name="pageID" /> <input type="hidden" value="<%=items.Name%>" name="sectionID" /> <input type="submit" value="GO!" /> </span> </li> <% counter = counter+1 bigCounter = bigCounter + 1 next Response.Write(arraySection) Response.Write("</ul>" & vbCrLf) Response.Write("</li>" & vbCrLf) end sub function MapURL(path) dim rootPath, url 'Convert a physical file path to a URL for hypertext links. rootPath = Server.MapPath("/") url = Right(path, Len(path) - Len(rootPath)) MapURL = Replace(url, "\", "/") end function %> </body> </html> Code (markup):
ok thanks that code helped. One thing I need now to distinguish is when it is a subdirectory as i need to work out the section place in the hiddenfield called sectionName ie it could be craig or could be craig/contact where contact is a sub directory of craig, does this make sense? See code i am using below. <ul class="mktree" id="tree1"> <ul><strong><%=siteName%></strong></ul> <% ListFolderContents(Server.MapPath("/site/scoles/jon")) ListFolderContents(Server.MapPath("/site/scoles/craig")) %> </ul> <% sub ListFolderContents(path) dim fs, fo , File, items, url set fs = CreateObject("Scripting.FileSystemObject") set fo = fs.GetFolder(path) 'Display the target folder and info. Response.Write("<li class=""liOpen""><b>" & fo.Name & "</b> " ) Response.Write("<ul>" & vbCrLf) 'Display a list of sub folders. for each item in fo.SubFolders ListFolderContents(item.Path) 'response.Write("kk") next 'Display a list of files. for each items in fo.Files 'url = MapURL(items.path) %> <form action="activeCodeStep2.asp" method="get"> <li><a href="#" onclick="return display_select('<%=bigCounter %>');"><%=items.Name %></a> <select name="pageOption" style="margin-top:0px; padding:0px;"> <option value="edit">Edit page <%=items.Name%></option> <option value="add">Add Page Below</option> <option value="addfolder">Create New Folder</option> </select> <input type="hidden" value="" name="sectionName" /> <input type="submit" value="GO!" /> </li> </form> <% next 'response.Write(mainCounter) Response.Write("</ul>" & vbCrLf) Response.Write("</li>" & vbCrLf) end sub function MapURL(path) dim rootPath, url 'Convert a physical file path to a URL for hypertext links. rootPath = Server.MapPath("/") url = Right(path, Len(path) - Len(rootPath)) MapURL = Replace(url, "\", "/") end function %> Code (markup):