p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   Classic ASP Professional (http://p2p.wrox.com/forumdisplay.php?f=63)
-   -   create array for loop in FSO (http://p2p.wrox.com/showthread.php?t=40969)

jfergy April 7th, 2006 03:19 PM

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...


Raghunathan April 13th, 2006 11:51 AM

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

jfergy April 13th, 2006 05:23 PM

Hello-

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


Raghunathan April 14th, 2006 02:17 AM

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

mat41 April 14th, 2006 09:59 PM

;;;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


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

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