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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

IIS/FSO help please

Status
Not open for further replies.

DreXor

Programmer
Jun 17, 2003
2,224
US
This is going to be a fun question ...

Is there any way to iterate through the virtual folders of IIS with FSO or other method in order to build site wide file lists? i understand how to issue a virtual or hardcoded path to FSO And loop thru folders and subfolders/files to get file list.

looking to cycle thru IIS somehow by a call to get a virtual folder list in IIS

thanks ahead of time.
 
Don't know if this is what you're looking for, but I whipped this up some time ago when I was bored :

Code:
<%@ Language=&quot;VBScript&quot; %>
<%
Sub folderDetails(folderName, indent)
        Dim fSystem, fObject, fFolder, fFiles, fIndent, newIndent
        fIndent = &quot;&quot;
        newIndent = indent + 3
        Set fSystem = Server.CreateObject(&quot;Scripting.FileSystemObject&quot;)
        Set fObject = fSystem.GetFolder(Server.MapPath(&quot;&quot; & folderName & &quot;&quot;))

        For i = 0 To indent
                fIndent = fIndent & &quot;&nbsp;&quot;
        Next

        For Each fFolder In fObject.SubFolders
                Response.Write(fIndent & &quot; - <a href='/&quot; & fFolder.Name & &quot;/' class='hyperlinks'>&quot; & fFolder.Name & &quot;</a><br>&quot;)
                folderDetails folderName & fFolder.Name & &quot;/&quot;, newIndent
        Next

        For Each fFiles In fObject.Files
                Response.Write(fIndent & &quot; - <span class='threadtext'>&quot; & fFiles.Name & &quot;</span><br>&quot;)
        Next

        Set fObject = Nothing
        Set fSystem = Nothing
End Sub

folderDetails &quot;/&quot;, 0
%>

As you can see, it starts at the root directory of the webserver and loops through each folder displaying all subfolders and files via iteration. I made the folder names links to add extra deliniation. Of course, you can play with formatting etc.

Let me know if this helps ?
 
Here's something a bit more advanced :

Code:
<%@ Language=&quot;VBScript&quot; %>
<html>
<head>
        <title><%= Request.ServerVariables(&quot;SERVER_NAME&quot;) %> :: Webserver Directory Listing</title>

<style type=&quot;text/css&quot;>
<!--
.bodytext {  font-family: Arial, Helvetica, sans-serif; font-size: 11pt; font-style: normal; color: #000000}
.caseheading {  font-family: Verdana; font-size: 10pt; font-style: normal; font-weight: bold; color: #3b2ea0}
.threadtext {  font-family: Arial, Helvetica, sans-serif; font-size: 10pt; font-style: normal; color: #000000}
.boldbody {  font-family: Arial, Helvetica, sans-serif; font-size: 11pt; font-style: normal; line-height: normal; font-weight: bold; color: #000000; text-decoration: none}
.hyperlink {  font-family: Arial, Helvetica, sans-serif; font-size: 10pt; font-style: normal; color: #3b2ea0; text-decoration: underline}
-->
</style>

</head>
<body>
<%
Sub folderDetails(folderName, indent)
        Dim fSystem, fObject, fFolder, fFiles, fIndent, newIndent, newSize
        fIndent = &quot;&quot;
        ' Indent the directory by 3
        newIndent = indent + 3
        Set fSystem = Server.CreateObject(&quot;Scripting.FileSystemObject&quot;)
        
        ' Get the specified folder
        Set fObject = fSystem.GetFolder(Server.MapPath(&quot;&quot; & folderName & &quot;&quot;))

        ' Set a string of non-breaking spaces for the indent
        For i = 0 To indent
                fIndent = fIndent & &quot;&nbsp;&quot;
        Next

        ' Loop through the subfolders
        For Each fFolder In fObject.SubFolders
                ' Output the subfolder name
                Response.Write(&quot;<tr><td colspan='3'>&quot; & fIndent & &quot; - <span class='hyperlink' style='text-decoration:none'>&quot; & fFolder.Name & &quot;</span></td></tr>&quot;)
                ' Call the folderDetails Sub using the current subfolder <-- Iteration
                folderDetails folderName & fFolder.Name & &quot;/&quot;, newIndent
        Next

        ' Loop through the files in the folder
        For Each fFiles In fObject.Files
                ' Output the file's name
                Response.Write(&quot;<tr class='threadtext'><td>&quot; & fIndent & &quot; - &quot; & fFiles.Name & &quot;</td>&quot;)

                ' Divide the file size by 1024 to get the size in kilobytes
                newSize = fFiles.Size / 1024
                ' Output the file's size
                Response.Write(&quot;<td>&quot; & Round(newSize, 1) & &quot; kb</td>&quot;)

                ' Ouput some file types different to standard ones to save space and aesthetics
                Select Case fFiles.Type
                        Case &quot;JPEG Image&quot;:
                                Response.Write(&quot;<td>jpeg Image</td>&quot;)
                        Case &quot;GIF Image&quot;:
                                Response.Write(&quot;<td>gif Image</td>&quot;)
                        Case &quot;Microsoft HTML Document 5.0&quot;:
                                Response.Write(&quot;<td>HTML Document</td>&quot;)
                        Case &quot;Cascading Style Sheet Document&quot;:
                                Response.Write(&quot;<td>CSS Document</td>&quot;)
                        Case &quot;ASP auto file&quot;:
                                Response.Write(&quot;<td>ASP source</td>&quot;)
                        Case &quot;INC File&quot;:
                                Response.Write(&quot;<td>Include File</td>&quot;)
                        Case &quot;JScript Script File&quot;:
                                Response.Write(&quot;<td>Javascript File</td>&quot;)
                        Case Else :
                                Response.Write(&quot;<td>&quot; & fFiles.Type & &quot;</td>&quot;)
                End Select

                ' Output the date last modified
                Response.Write(&quot;<td>&quot; & fFiles.DateLastModified & &quot;</td></tr>&quot;)
        Next

        Set fObject = Nothing
        Set fSystem = Nothing
End Sub

' Build a table to show the directory listing
Response.Write(&quot;<table width='100%'>&quot;)
' Output the headings for the table
Response.Write(&quot;<tr class='caseheading'><td>&nbsp;Name</td><td>Size</td><td>Type</td><td>Last Modified</td></tr>&quot;)
Response.Write(&quot;<tr><td>&nbsp;</td></tr>&quot;)
' Call folderDetails Sub with the root directory, so that it iterates through all the directories on the server
folderDetails &quot;/&quot;, 0
' End the table
Response.Write(&quot;</table>&quot;)
%>
</body>
</html>


I would work on some javascript so that you can collapse/expand directories, but I really should be getting back to work.

Damon
 
i already have a subfolder enumerator without a problem it's the non physical folders that i'm looking for, the virtual folders that in other directory structures specified in IIS i appreciate the posts though.


Example : &quot;/&quot; web root - c:\inetpub\ &quot;/music&quot; Music drive - m:\mp3\music
using FSO without feeding it &quot;/music&quot; will never display &quot;/music&quot; and subfolders without telling it to, because the virtual folder is only referenced and used by IIS, i'm trying to find out if there's a way to list the virtual contents of the root.

thanks again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top