Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

display folders and subfolders...

Status
Not open for further replies.

cawi17

IS-IT--Management
Oct 25, 2002
18
0
0
MY
I'm trying to display my folders and subfolders of a parent folder in format exactly like :

[Parent Folder 1
[SubFolder1,
[Folder2],
[Folder3],
[Folder4]
],
[SubFolder2,
[Folder2],
[Folder3],
[Folder4]
],
]



but it didn't work. The part which i'm unable to figure is when to put the the ']' after each subfolder.... could anybody help...?



'codes below '
***********************************************************

<%

makefolder("C:\Program Files\")

Sub makefolder(path)

dim fs,fo,x,i

set fs=Server.CreateObject("Scripting.FileSystemObject")
set fo=fs.GetFolder(path)

for each x in fo.SubFolders
'Print the name of all subfolders in the test folder

if x.SubFolders.Count > 0 Then
Response.write(" , <br>")
makefolder(x.Path)
else
Response.write(" ] , <br>")
End if

Response.write("<BR>")

Response.write(" ] ,<br>")

next

set fo=nothing
set fs=nothing
End Sub

%>





p/s : Thank you...
 
oohh i forgot... the indentation for the display could be ignored....
 
this is a funtion i used in making a windows explorer style web page.

Code:
Function BuildTree(FullPath,Depth)
  Tree = Split(FullPath,"\")
  If Tree(Depth) <> "" Then
    If Depth < 1 Then
      CurrentPath= CurrentPath & Tree(Depth) & "\"
    Else
      CurrentPath = Replace(CurrentPath & "\" & Tree(Depth),"\\","\")
    End If

    Set CurrentFolder = FS.GetFolder(CurrentPath)
    TabCount = TabCount + 1
    For each SubFolder in CurrentFolder.SubFolders
      If Not ChkArray(FolderExclusions,Subfolder.Name,"|") Then
        If Depth < Ubound(Tree) Then
          If Depth = Ubound(Tree)-1 AND StrComp(SubFolder.Name,Tree(Depth+1),vbtextcompare) = 0 Then
            AnchorFlagged = True
          Else
            AnchorFlagged = False
          End If
          If StrComp(SubFolder.Name,Tree(Depth+1),vbtextcompare) = 0 Then
            Style="folderopen"
            SubStyle=" class=""current"""
            Branch = True
          Else
            Style="folder"
            SubStyle=""
            Branch = False
          End If
        Else
          Style="folder"
          SubStyle=""
          Branch = False
      End If
%>
<%=indent(TabCount)%><li class="<%=Style%>">
<%
        If AnchorFlagged Then
%>
<%=indent(TabCount)%><a id="A"></a>
<%
        End If
%>
<%=indent(TabCount+1)%><div<%=substyle%> onclick="postme('<%=Server.HTMLEncode(JavaFriendly(SubFolder))%>');"<%If SubStyle = "" Then%><%End If%>><%=SubFolder.Name%></div>
<%
        If Branch Then
%>
<%=indent(TabCount+1)%><ul>
<%
            thisvar = BuildTree(FullPath,Depth+1)
%>
<%=indent(TabCount-1)%></ul>
<%
        End If
%>
<%=indent(TabCount-1)%></li>
<%
      End If
    Next
    Set CurrentFolder = nothing
  End If
End Function


it recurses itself for the sub folders. and is originally called by :

thisvar = BuildTree("C:\",0)


the style/classes used in this are because of the LI and UL tags, it allows for you to use folder images instead of bullets:

LI {white-space: nowrap;cursor:hand; margin:0;}
.parent {list-style-image:url(<%=ImgUpFolder%>);}
.comp {list-style-image:url(<%=ImgComp%>);}
.fd {list-style-image:url(<%=ImgFD%>);}
.hd {list-style-image:url(<%=ImgHD%>);}
.cd {list-style-image:url(<%=ImgCD%>);}
.nd {list-style-image:url(<%=ImgND%>);}
.folder {list-style-image:url(<%=ImgFold%>);}
.folderopen {list-style-image:url(<%=ImgFoldOpen%>);}
.current {font-weight: bold;}
.file {list-style-image: url(<%=ImgFile%>);}
.filemedia {list-style-image: url(<%=ImgFileMedia%>);}
.filezip {list-style-image: url(<%=ImgFileZip%>);}
.filetxt {list-style-image: url(<%=ImgFileTxt%>);}
.scroll {scrollbar-arrow-color:<%=ScrollBarBase%>; scrollbar-base-color:<%=ScrollBarBase%>; scrollbar-face-color:<%=ScrollBarBright%>; scrollbar-highlight-color:<%=ScrollBarDark%>;}


the variables in the style relate to page style variables for the images :

ImgSearch = "/images/folders/Custom/a_s_Search.gif"
ImgUpFold = "/images/folders/Custom/a_s_upfold.gif"
ImgComp = "/images/folders/Custom/a_s_comp1.gif"
ImgFD = "/images/folders/Custom/a_s_FD.gif"
ImgHD = "/images/folders/Custom/a_s_HD.gif"
ImgCD = "/images/folders/Custom/a_s_CD.gif"
ImgND = "/images/folders/Custom/a_s_ND.gif"
ImgFold = "/images/folders/Custom/a_s_folder.gif"
ImgFoldOpen = "/images/folders/Custom/a_s_folder_open.gif"
ImgFile = "/images/folders/Custom/a_s_file.gif"
ImgFileMedia = "/images/folders/Custom/a_s_FileMedia.gif"
ImgFileZip = "/images/folders/Custom/a_s_FileZip.gif"
ImgFileTxt = "/images/folders/Custom/a_s_FileTxt.gif"




hope the info helps

[thumbsup2]DreX
aKa - Robert
if all else fails, light it on fire and do the happy dance!
 
oops, forgot to note, folderexclusions is a variable for handling folder that shouldn't be listed, such as recycled or system volume information

indent is a function for making the html view source "friendly" so that not everything is rammed back to back or all the way to the left side

anchorflagged is a variable for adding a <a> tag to the document so if you have this in a frame or scrolling div that you can use JS : scrollIntoView so that the folder doesn't need to be scrolled to that you're accessing.

looking over the code, you might want these addional functions used in the page :

Code:
Function Indent(Tabs)
    Indent = ""
    For TabCounter = 1 to Tabs
        Indent = Indent & "    "
    Next
    TabCount = Tabs
End Function

Function Javafriendly(Junk)
    Javafriendly = Replace(Replace(junk,"\","\\"),"'","\'")
End Function

Function ChkArray(Values,Value,Delim) 'returns true/false on a comparitive set
    If ISArray(Values) Then
        ChkArrayArr = Values
    Else
        ChkArrayArr = Split(Values,Delim)
    End If
    ChkArray = False
    For ChkArrayArrCounter=0 to Ubound(ChkArrayArr)
        If StrComp(ChkArrayArr(ChkArrayArrCounter),Value,vbTextCompare) = 0 Then
            ChkArray = True
        End If
    Next
End Function

ps in case of copy/paste .. the prior post the lines :
<%=indent(TabCount+1)%><div<%=substyle%> onclick="postme('<%=Server.HTMLEncode(JavaFriendly(SubFolder))%>');"<%If SubStyle = "" Then%><%End If%>><%=SubFolder.Name%></div>

is _1_ line, make sure to remove the line break from wrapping.



[thumbsup2]DreX
aKa - Robert
if all else fails, light it on fire and do the happy dance!
 

thanqs DreXor for the helpful reply.... I'm trying the codes now..... mmm.... but still if it's possible.... do you know how to generate the folder and file list exactly like the format.... it is actually because I found I script on the 'link tree' , and it uses the exact format of javascript to generate the items for the tree....

thanq....

 
hmm .. along the formatting above ... as close to format and so forth thus far :

Code:
<%
Response.Expires = -1
public FS, Depth, currentpath, fullpath

Set FS = server.CreateObject("Scripting.FileSystemObject")
%>
<html>
<body>
<%Temp = Buildtree("C:\temp",0)%>
</body>
</html>
<%
Set FS = nothing


function buildtree(fullpath,depth)
  Tree = Split(fullpath,"\")
  If Depth <= Ubound(Tree) Then
  If Tree(Depth) <> "" Then
    If Depth < 1 Then
      CurrentPath= CurrentPath & Tree(Depth) & "\"
      Response.Write "[" & currentpath & ",<br>"
    Else
      CurrentPath = Replace(CurrentPath & "\" & Tree(Depth),"\\","\")
    End If
    Set CurrentFolder = FS.GetFolder(CurrentPath)
    For each SubFolder in CurrentFolder.SubFolders
        If Depth < Ubound(Tree) Then
          If StrComp(SubFolder.Name,Tree(Depth+1),vbtextcompare) = 0 Then
            Branch = True
          Else
            Branch = False
          End If
        Else
          Branch = True
        End If

        Response.Write Replace(space((depth+1) * 4)," ","&nbsp;") & "[" & SubFolder.Name
        If Branch Then
            Response.write ",<br>"
            thisvar = BuildTree(fullpath,Depth+1)
        Else
            Response.Write "]<br>" & vbcrlf
        End If
    Next
    Response.Write Replace(space((depth) * 4)," ","&nbsp;") & "]<br>" & vbcrlf
    Set CurrentFolder = nothing
  End If
  End If
end function
%>



[thumbsup2]DreX
aKa - Robert
if all else fails, light it on fire and do the happy dance!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top