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!

Reading files from a folder

Status
Not open for further replies.

mdr2271

Programmer
Sep 14, 2005
42
US
Does anyone have any code that will let an ASP read files from a folder in the website? Also, how can one read the folder structure? I am trying to read the files underneath a folder where users can upload their own files and also create subfolders. Thanks.
 
I am not sure that is possible. It wouldn't be a very neighborly thing to, would it...;)
 
Basically there are 3 ways to interpret your request:
1) Read and display the file structure on your web server (covered above)
2) read and display the file structure on someone elses web server (yikes)
3) read and display the file structure on another server you (or your company) owns that the web server has access to (slightly more difficult than #1, but doable)

Let us know which of these your after and, ifthe above posts don't cover it, we should be able to provide more information

If you are looking to do #2, you will probably need to look elsewhere. If there is a solution to that, besides brute force, I would not want to see it posted on the forums, as it would be too easy for someone to misuse it, or rather, use it for less-than-innocent gains.

 
Basically what I am trying to do is take an area on my website that I users can upload files to (via a file upload process in the html web editor I am using) and read the folder name and filename into a database table.

For example, if I have a folder called files with a subfolder called pictures and someone uploads the files pic1.jpg, pic2.jpg and pic3.jpg I want to be able read the following into my table:

\files\pictures\pic1.jpg
\files\pictures\pic2.jpg
\files\pictures\pic3.jpg
 
this code reads all the files in the current folder where the page is setting that you put this code in. Its based on the code from what DotNetGnat posted in the link above.
Code:
<%
	Dim strPath   'Path of directory to show
	Dim objFSO    
	Dim objFolder 
	Dim objItem   
	strPath="./"
	Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
	Set objFolder = objFSO.GetFolder(Server.MapPath(strPath))
	
	response.write "<TABLE>" &_
	 	"<tr><TD>Description</td>" &_
	 	"<TD>Size</TD>" &_
	 	"<TD>Date</TD></TR>"
	For Each objItem In objFolder.Files
		
	 		response.write "<tr><TD><A HREF=""" &_
	   		strPath & objItem.Name &_
	  		""">" & objItem.Name & "</A></TD>" &_
	  		"<TD>" & objItem.Size & "</TD>" &_
	  		"<TD>"& objItem.DateCreated & "</TD></TR>"
	  	
	Next
	response.write "</TABLE>"
	Set objItem = Nothing
	Set objFolder = Nothing
	Set objFSO = Nothing

%>
mdr2273,
Don't know if this will help but it accomplished what I wanted to do.

Thanks all

DougP, MCP, A+
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top