Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Search | Today's Posts | Mark Forums Read
Classic ASP Professional For advanced coder questions in ASP 3. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old April 7th, 2006, 03:19 PM
Authorized User
 
Join Date: Jan 2006
Location: , , .
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Default create array for loop in FSO

Hello-

I have files in a folder named listingID.jpg through listingIDj.jpg

How can I use the file system object to check each file and if it exists put it into a for loop for display? I need to do this for a dynamic xml page that can only use 1 call. So something like this:

fso.fileexists(my array)
for each in my array
response.write ""

loop
etc...

Reply With Quote
  #2 (permalink)  
Old April 13th, 2006, 11:51 AM
Authorized User
 
Join Date: Mar 2006
Location: Chennai, Tamil Nadu, India.
Posts: 32
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to Raghunathan
Default

hi,

here is the code u asked for. i hope it satisfies ur need.

================================================== ====
Dim objFSO, objFolder, objFiles, objFile
Dim strFolderPath

strFolderPath = "C:\MyFolder" 'Exact Path of the Folder


Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(strFolderPath)
Set objFiles = objFolder.Files

For Each objFile In objFiles
   Response.Write objFile.Path & "\" & objFile.Name
Next

Set objFSO = Nothing
Set objFolder = Nothing
Set objFiles = Nothing

================================================== =

here you dont have to check for the existence of the file, as when u iterate thru the collection, it gets only the available files from the folder




Regards,
Raghu
Reply With Quote
  #3 (permalink)  
Old April 13th, 2006, 05:23 PM
Authorized User
 
Join Date: Jan 2006
Location: , , .
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hello-

That wont help, I need to check for specific files in the folder not return all of them. Thanks anyway

Reply With Quote
  #4 (permalink)  
Old April 14th, 2006, 02:17 AM
Authorized User
 
Join Date: Mar 2006
Location: Chennai, Tamil Nadu, India.
Posts: 32
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to Raghunathan
Default

hi,

i hope this code will surely help your needs, pls gimme your feedback.

Dim ObjFSO
Dim ObjFolder
Dim ObjFile

Set ObjFSO = Server.CreateObject("Scripting.FileSystemObject")
Set ObjFolder = ObjFSO.GetFolder("C:\MyFolder") 'folder path

For Each ObjFile In ObjFolder.Files
    If InStr(1, ObjFile.Name, "library", vbTextCompare) > 0 And _
              LCase(ObjFSO.GetExtensionName(ObjFile.Path)) = "jpg" Then
        Response.Write ObjFile.Path & "<BR>"
    End If
Next

Regards,
Raghu
Reply With Quote
  #5 (permalink)  
Old April 14th, 2006, 09:59 PM
Friend of Wrox
Points: 6,664, Level: 34
Points: 6,664, Level: 34 Points: 6,664, Level: 34 Points: 6,664, Level: 34
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2004
Location: Sydney, NSW, Australia.
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41
Default

;;;I have files in a folder named listingID.jpg through listingIDj.jpg
A folder named listingID.jpg - interesting folder name, do you mean this is a file name?

BTW: if a file doesnt exist this code will simply not show it. I hope I have undertood your objective.

Anyhow, place this file (its cut and paste) in the dir that you want listed:

<%
  Dim strPathInfo, strPhysicalPath
  strPathInfo = Request.ServerVariables("PATH_INFO")
  strPhysicalPath = Server.MapPath(strPathInfo)

  Dim objFSO, objFile, objFileItem, objFolder, objFolderContents

  Set objFSO = CreateObject("Scripting.FileSystemObject")
  Set objFile = objFSO.GetFile(strPhysicalPath)
  Set objFolder = objFile.ParentFolder
  Set objFolderContents = objFolder.Files
%>
<HTML>
 <HEAD>
  <TITLE>Display Directory</TITLE>
 </HEAD>
<BODY>
<TABLE cellpadding=5>
 <TR align=center>
  <td align=left>File Name</td>
  <td>File Size</td>
  <td>Last Modified</td>
</TR>
<%
  For Each objFileItem In objFolderContents
    Response.Write "<TR><TD align=left>"
    Response.Write objFileItem.Name
    Response.Write "</TD><TD align=right>"
    Response.Write objFileItem.Size
    Response.Write "</TD><TD align=right>"
    Response.Write objFileItem.DateLastModified
    Response.Write "</TD></TR>"
  Next
%>

</TABLE>
</BODY>
</HTML>

Wind is your friend
Matt
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with Array and Loop ublend Classic ASP Professional 2 November 21st, 2007 07:50 AM
loop array problem dbrine Java Basics 2 June 15th, 2007 06:49 AM
Problem with loop and array katlees MySQL 1 July 5th, 2006 11:24 PM
Pass variables from array inside a loop dustygn PHP How-To 2 May 3rd, 2006 05:35 PM



All times are GMT -4. The time now is 02:04 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.