To read the article online, visit http://www.4GuysFromRolla.com/webtech/092998-3.shtml

VBScript DIR Function


This code was written by Toby Gramm, webmaster of Techfools.com.


DIR


Yep it's kinda like the old school DOS days.

Put this code in a file and name it "dir.asp", make sure that this is used in a secure directory, cuz this has to potenial to expose you whole file system to the Web! Can be very useful, can also shoot you in the foot. Use this wisely!

Example:
http://www.techfools.com/code/dir/dir.asp?PP=G:\InetPub\wwwroot\techfools\code\dir\&UU=http://www.techfools.com/code/dir/
Note: Of course you would URLencode this.

Result:
Folder

code.txt
default.asp
fCount.asp
Sample.asp

Da' Code


<%@ LANGUAGE="VBSCRIPT" %>
<%

'Written by: Toby Gramm
'070698
'Modified 092998 - Added support for Folders.
'		   As suggested by Bill Wilkinson [BillW@chilisoft.com]

Sub Main()
	sPP = Request.QueryString("PP") 'Physical Path
	sUP = Request.QueryString("UP") 'URL Path

	Set fso = CreateObject("Scripting.FileSystemObject")
	Set f = fso.GetFolder(sPP)  
	Set fc = f.Files 
	Set ff = f.SubFolders 
	For Each f1 in ff	
  	  Response.Write "<a href=" & sUP & f1.name & ">" & f1.name & "</a> <br>"
	Next  
	Response.Write "<br>"
	For Each f1 in fc
	  Response.Write "<a href=" & sUP & f1.name & ">" & f1.name & "</a> <br>"
	Next  
	Set ff = nothing
	Set fso = nothing
	Set f = nothing
	Set fc = nothing
End Sub
%>
Main()


[Visit Techfools.com] [Email Webmaster]


Article Information
Article Title: VBScript DIR Function
Article Author: Scott Mitchell
Published Date: Tuesday, September 29, 1998
Article URL: http://www.4GuysFromRolla.com/webtech/092998-3.shtml


Copyright 2017 QuinStreet Inc. All Rights Reserved.
Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers