All source code in ASP/ VbScript Ask a ASP/ VbScript Pro Discussion Forum Categories All jobs in ASP/ VbScript
Quick Search for:  in language:    
dynamically,show,contents,directory,want
   Code/Articles » |  Newest/Best » |  Community » |  Jobs » |  Other » |  Goto » | 
CategoriesSearch Newest CodeCoding ContestCode of the DayAsk A ProJobsUpload
ASP/ VbScript Stats

 Code: 281,486. lines
 Jobs: 101. postings

 How to support the site

 
Sponsored by:

 
You are in:
 
Login

NEW! LEARNING CENTER
Special educational offers, white papers, webcasts, podcasts

  NEW! Download Rational Performance Tester V8 (download now)
  NEW! Download Rational Functional Tester V8 (download now)
  NEW! Download Rational Service Tester for SOA Quality V8 (download now)
  NEW! Teleconference: Quality In Action - Using Rational Quality Manager with Functional, Performance and Web Service Testing Products (download now)
  NEW! Introducing IBM Rational AppScan Developer Edition – easing security testing by non-security professionals (download now)

 

 


Latest postings for ASP/ VbScript.
Click here to see a screenshot of this code!Mess Officer Management System (Sistem Pengurusan Mess Pegawai)
By Mohd Fauzi on 11/23

(Screen Shot)

Click here to put this ticker on your site!


Add this ticker to your desktop!


Daily Code Email
To join the 'Code of the Day' Mailing List click here!



 
 
   

Directory Listing

Print
Email
 
VB icon
Submitted on: 11/26/2000 1:41:55 AM
By: Kaustav Acharya  
Level: Beginner
User Rating: By 8 Users
Compatibility:ASP (Active Server Pages), HTML, VbScript (browser/client side)

Users have accessed this code 31758 times.
 
author picture
(About the author)
 
     To dynamically show contents in a directory (any one you want)

 
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!

    '**************************************
    ' for :Directory Listing
    '**************************************
    if you think this script is good, please rate it appropriately. I would really like that! :D
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
1) You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.   
2) You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
3) You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
4) You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.

    '**************************************
    ' Name: Directory Listing
    ' Description:To dynamically show conten
    '     ts in a directory (any one you want)
    ' By: Kaustav Acharya
    '
    ' Returns:Contents of a directory with t
    '     he following info: name of the file/subd
    '     irectory, link to the file/subdirectory,
    '     images for the type of file
    '
    ' Assumes:You would need to get the pict
    '     ures you would want for each type of fil
    '     e in your directory. If you have only on
    '     e type just define it in the code below 
    '     to shorten the script.
    if you would like To see a working copy, please go to http://www15.brinkster.com/infinityprod/index.asp
    '
    ' Side Effects:None that I am aware of
    '
    'This code is copyrighted and has    ' limited warranties.Please see http://w
    '     ww.Planet-Source-Code.com/vb/scripts/Sho
    '     wCode.asp?txtCodeId=6392&lngWId=4    'for details.    '**************************************
    
    <!DOCTYPE html Public "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML>
    <HEAD>
    <TITLE>Directory listing of MP3s</TITLE>
    </HEAD>
    <BODY bgcolor="#000000" text="#400080" link="#400080" vlink="#FFFF80">
    <%
    Dim dirname, mypath, fso, folder, filez, FileCount
    dirname = "../mp3s/"
    mypath = "../mp3s/"
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set folder = fso.GetFolder(server.mappath(dirname))
    Set filez = folder.Files
    FileCount = folder.Files.Count
    ' This function takes a filename and ret
    '     urns the appropriate image for
    ' that file type based on it's extension
    '     . If you pass it "dir", it assumes
    ' that the corresponding item is a direc
    '     tory and shows the folder icon.
    function ShowImageForType(strName)
    	Dim strTemp
    	' Set our working String To the one passed in
    	strTemp = strName
    	
    	' if it's Not a directory, Get the extension and Set it to strTemp
    	' if it is a directory, Then we already have the correct value
    	if strTemp <> "dir" Then
    		strTemp = LCase(Right(strTemp, Len(strTemp) - InStrRev(strTemp, ".", -1, 1)))
    	End if
    	
    	response.write strTemp
    	
    	' Set the part of the image file name that's unique To the Type of file
    	' To it's correct value and Set this to strTemp. (yet another use of it!)
    	Select Case strTemp
    		Case "mp3"
    			strTemp = "MP3"
    		Case "mp2"
    			strTemp = "MP3"
    		Case "wav"
    			strTemp = "MP3"
    		Case "aiff" 
    			strTemp = "MP3"
    		Case "html"
    			strTemp = "htm"
    		Case "m3u"
    			strTemp = "MP3"
    		End Select
    	' All our logic is done... build the IMG Tag For display To the browser
    	' Place it into... where else... strTemp!
    	' My images are all GIFs and all start With "dir_" For my own sanity.
    	' They End With one of the values Set In the Select statement above.
    	strTemp = "<IMG SRC=""images/dir_" & strTemp & ".gif"" WIDTH=16 HEIGHT=16 BORDER=0>"
    	' Set return value and Exit function
    	ShowImageForType = strTemp
    End function
    'That's it for functions on this one!
    %>
    <%' Now To the Runtime code:
    Dim strPath 'Path of directory to show
    Dim objFSO 'FileSystemObject variable
    Dim objFolder 'Folder variable
    Dim objItem 'Variable used To Loop through the contents of the folder
    ' You could just as easily read this fro
    '     m some sort of input, but I don't
    ' need you guys and gals roaming around 
    '     our server so I've hard coded it to
    ' a directory I set up to illustrate the
    '     sample.
    ' NOTE: As currently implemented, this n
    '     eeds to end with the /
    strPath = mypath
    ' Create our FSO
    Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
    ' Get a handle on our folder
    Set objFolder = objFSO.GetFolder(Server.MapPath(strPath))
    ' Show a little description line and the
    '     title row of our table
    %>
    <CENTER><FONT face="Arial" color="#9690CC">
    <%= FileCount %> Contents of <B><I>
    <%= strPath %></I> Not Counting Any Folders</B></CENTER></FONT><BR><BR>
    <TABLE align="center" border="5" bordercolor="#010194" cellspacing="0" cellpadding="2">
    	<TR bgcolor="#010194">
    		<TD align="CENTER"><FONT face="Arial" color="#FFFFFF"><B>File Name:</B></FONT>
    		</TD>
    		<TD align="CENTER"><FONT face="Arial" color="#FFFFFF"><B>File Size (MB):</B></FONT>
    		</TD>
    		<TD align="CENTER"><FONT face="Arial" color="#FFFFFF"><B>Date Created:</B></FONT>
    		</TD>
    		<TD align="CENTER"><FONT face="Arial" color="#FFFFFF"><B>File Type:</B></FONT>
    		</TD>
    	</TR>
    	<%
    ' First I deal with any subdirectories. 
    '     I just display them and when you
    ' click you go to them via plain HTTP. Y
    '     ou might want to loop them back
    ' through this file once you've set it u
    '     p to take a path as input.
    For Each objItem In objFolder.SubFolders
    	' Deal With the bad VTI's that keep giving our visitors 404's
    	
    	if InStr(1, objItem, "_vti", 1) = 0 Then
    	%>
    	
    	<TR bgcolor="#87BCFE">
    		<TD align="left">
    			<%= ShowImageForType("dir") %> <A href="<%= strPath & objItem.Name %>">
    			<%= objItem.Name %></A>
    		</TD>
    		<TD align="right">
    			<%= objItem.Size/1000000 'I used this To display the file size In MB, you can Set it to default
    			%>
    			
    		</TD>
    		<TD align="left">
    			<%= objItem.DateCreated 'date of creation
    			%>
    		</TD>
    		<TD align="left">
    			<%= objItem.Type 'the type of file 
    			%> 
    		</TD>
    	</TR>
    	<%
    	End if
    Next 'objItem
    ' Now that I've done the SubFolders, do 
    '     the files!
    For Each objItem In objFolder.Files
    %>
    	<TR bgcolor="#87BCFE">
    		<TD align="left">
    			<%= ShowImageForType(objItem.Name) %> <A href="<%= strPath & objItem.Name %>">
    			<%= objItem.Name %></A>
    		</TD>
    		<TD align="right">
    			<%= objItem.Size/1000000 %>
    		</TD>
    		<TD align="left">
    			<%= objItem.DateCreated %>
    		</TD>
    		<TD align="left">
    			<%= objItem.Type %>
    		</TD>
    	</TR>
    	<%
    Next 'objItem
    Set objItem = Nothing
    Set objFolder = Nothing
    ' All done! Kill off the object variable
    '     s.
    Set objFSO = Nothing
    %>
    </TABLE>
    </BODY>
    </HTML>


Other 6 submission(s) by this author

 

 
 Report Bad Submission
Use this form to notify us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:
 
Your Vote!

What do you think of this code(in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor See Voting Log
 
Other User Comments
6/23/2002 12:19:48 AMTim Garrison

Not bad. I would get rid of the images in it if i were you... It kept giving me a 500 error.

Other than that it works great!
(If this comment was disrespectful, please report it.)

 
2/6/2003 11:39:55 AMGavin Gault

BAH this code has just been copied from http://www.asp101.com/samples/dir_list.asp you might have at least done someting diffrent with it instead of passing it off as your own code LOL
(If this comment was disrespectful, please report it.)

 
Add Your Feedback!
Note:Not only will your feedback be posted, but an email will be sent to the code's author from the email account you registered on the site, so you can correspond directly.

NOTICE: The author of this code has been kind enough to share it with you.  If you have a criticism, please state it politely or it will be deleted.

For feedback not related to this particular code, please click here.
 
To post feedback, first please login.


 

Categories | Articles and Tutorials | Advanced Search | Recommended Reading | Upload | Newest Code | Code of the Month | Code of the Day | All Time Hall of Fame | Coding Contest | Search for a job | Post a Job | Ask a Pro Discussion Forum | Live Chat | Feedback | Customize | ASP/ VbScript Home | Site Home | Other Sites | Open Letter from Moderators | About the Site | Feedback | Link to the Site | Awards | Advertising | Privacy

Copyright© 1997-2008 by Exhedra Solutions, Inc. All Rights Reserved.  By using this site you agree to its Terms and Conditions.   Planet Source Code (tm) and the phrase "Dream It. Code It" (tm) are trademarks of Exhedra Solutions, Inc.