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

display files/ folders

Status
Not open for further replies.

ckennerdale

Programmer
Dec 23, 2000
158
GB
Hi

hopefully someone can help.

I know absolutly no ASP (I am a php developer).
what i want to do is have an index page in a folder, which when viewed just lists all the files and folders as links (which can then be downloaded or viewed)

I can do this in about 10 lines of php code, but am finding an asp alternative difficult to find.

Can anyone point me in the right direction?

cheers

Caspar Kennerdale
 
I can't remember who I got this from, but it was someone on another forum, and this is awesome code. All credit to whoever that was, not me!!

Simple (where strDir is a path to the diectory, or just "./"):
Code:
<html><body>
<%
dim fname,fso,f,sf,fil,strDir

Set fso=Server.CreateObject(&quot;Scripting.FileSystemObject&quot;) 
Set f = fso.GetFolder(strDir)
   For Each sf in f.SubFolders
        response.write &quot;folder : &quot; & sf.Name&&quot;<br />&quot; & vbcrlf
   Next
   For Each fil In f.Files
      Response.write &quot;file: &quot; & fil.Name&&quot;<br/>&quot; & vbcrlf
   Next
set fso = Nothing
%>
</body></html>

Clever:
Code:
<html><body>
<style>
a {
	color:blue;
}
body {
	font-family:verdana,arial,helvetica;
	font-size:9px;
}
.indent{
    margin-left:20px;margin-right:10px;
    display:none;
}
</style>
<script language=&quot;Javascript&quot;>
    function tog(i)
    {
         var o = document.getElementById(i);
         if (o.style.display=='block')
         {
              o.style.display='none';
         }else{
              o.style.display='block';
         };
    }
</script>
<%
outputfolder server.MapPath(&quot;.&quot;),0,3

sub OutputFolder(path, level, maxlevel)
    dim fname,fso,f,sf,fil
    Set fso=Server.CreateObject(&quot;Scripting.FileSystemObject&quot;) 
    Set f = fso.GetFolder(path)
    fname = &quot;[&quot; & f.name & &quot; (&quot; & f.Files.Count & &quot;)]&quot;
    if level<maxlevel then 
         fname = &quot;<a name=&quot;&quot;&quot; &_
	    replace(f.path,&quot;\&quot;,&quot;\\&quot;) & &quot;&quot;&quot; href=&quot;&quot;#&quot;&_
	    replace(f.path,&quot;\&quot;,&quot;\\&quot;) & &quot;&quot;&quot; onclick=&quot;&quot;tog('&quot; & _
         replace(f.path,&quot;\&quot;,&quot;\\&quot;)&&quot;')&quot;&quot;>&quot; & fname & &quot;</a>&quot;
    end if
    Response.Write fname & &quot;<br>&quot;
    if level<maxlevel then 
         Response.Write &quot;<div class=indent id=&quot;&quot;&quot;&f.path&&quot;&quot;&quot;>&quot;
         For Each sf in f.SubFolders
              outputFolder sf.path, level+1, maxlevel
         Next
         For Each fil In f.Files
            Response.write fil.Name&&quot;<br>&quot;
         Next
         Response.Write &quot;</div>&quot;
    end if
    set fso = Nothing
end sub
%>
</body></html>

--------------------------------------------------
- better than toast.
Penguins - better than --------------------------------------------------
 
You can play around with this

<html><body>
<%
Dim strFolderName()

Dim fs
set fs = server.CreateObject(&quot;Scripting.FileSystemObject&quot;)
Dim i

ReDim strFolderName(1)
strFolderName(0) = &quot;D:\INETPUB\getfolder (strFolderName(0))
i = 0
Do While i < UBound(strFolderName)
Response.Write &quot;No:&quot;&i&&quot; &quot;& strFolderName(i) & &quot;<br>&quot; & vbcrlf
i = i + 1
Loop


Sub getfolder(strFolder)
Dim fs
set fs = server.CreateObject(&quot;Scripting.FileSystemObject&quot;)

Set fld = fs.getfolder(strFolder)
For Each sfld In fld.SubFolders
ReDim Preserve strFolderName(UBound(strFolderName) + 1)
strFolderName(UBound(strFolderName)) = sfld.Path
getfolder (sfld.Path)
Next
End Sub
%>
</body></html>
 
Place a star if the thread was helpful, that way we know which ones are solved
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top