VB icon

File / Directory Viewer

Email
Submitted on: 1/5/2015 7:24:00 AM
By: Thomas Michael (from psc cd)  
Level: Beginner
User Rating: By 13 Users
Compatibility: ASP (Active Server Pages), VbScript (browser/client side)
Views: 1209
 
     This Will Display All The Files, File Size and file date of every file in the directory you specify. To make this work, paste the code into your favorite html editor, save it and then view it.

 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
'**************************************
' Name: File / Directory Viewer
' Description:This Will Display All The Files, File Size and file date of every file in the directory you specify.
To make this work, paste the code into your favorite html editor, save it and then view it.
' By: Thomas Michael (from psc cd)
'
' Assumes:File System Object Be Needed :) and it is setup to look for you my documents folder at "c:\mydocu~1" but you can change the line of code to look in any directory.
'**************************************

<%@ LANGUAGE="VBSCRIPT" %>
<% Option Explicit %>
<HTML>
<HEAD> <TITLE>File Viewer</TITLE> </HEAD>
<BODY>
<Table width="100%" border=1 bordercolor="#000000" align="left" cellpadding="2" cellspacing="0">
<Tr align="left" valign="top" bgcolor="#000000"> 
	<TD width="65%"><font color="#FFFFFF"><b><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Title</font></b></font></Td>
<Td width="10%"><font color="#FFFFFF"><b><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Size</font></b></font></Td>
<Td width="25%"><font color="#FFFFFF"><b><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Date</font></b></font></Td>
</Tr>
 <%
	'File System Object
	dim objFSO
	'File Object
	dim objFile
	'Folder Object
	dim objFolder
	'String To Store The Real Path
	dim sMapPath
	'Create File System Object to get list of files
	Set objFSO = CreateObject("Scripting.FileSystemObject")
	'Get The path for the web page and its dir.
	'change this setting to view different directories
	sMapPath = "C:\Mydocu~1"
	'Set the object folder to the mapped path
	Set objFolder = objFSO.GetFolder(sMapPath)
	'For Each file in the folder
	For Each objFile in objFolder.Files
	%> 
	<TR align="left" valign="top" bordercolor="#999999" bgcolor="#FFFFFF"> 
	<TD> <font size="2" face="Verdana, Arial, Helvetica, sans-serif" color="#000000"><A href="<% = sMapPath & "/" & objFile.Name %>"> 
	<%
			'write the files name
			Response.Write objFile.Name
	%>
	</a>
	</font>
	</TD>
<TD>
	<font size="2" face="Verdana, Arial, Helvetica, sans-serif" color="#000000">
	
	<%
			'We will format the file size so it looks pretty
			If objFile.Size <1024 Then
				Response.Write objFile.Size & " Bytes"
			ElseIF objFile.Size < 1048576 Then
				Response.Write Round(objFile.Size / 1024.1) & " KB"
			Else
				Response.Write Round((objFile.Size/1024)/1024.1) & " MB"
			End If
	%>
	</font>
	</TD>
<TD>
		<font size="2" face="Verdana, Arial, Helvetica, sans-serif" color="#000000">
			<%	'the files date 
				Response.Write objFile.DateLastModified
			%>
		</font>
	</TD>
	</font>
	</TD>
	</Tr>
	<%
		Next
	%> 
</Table>
</BODY>
</HTML>


Other 2 submission(s) by this author

 


Report Bad Submission
Use this form to tell 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


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.