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

April 7th, 2006, 03:19 PM
|
|
Authorized User
|
|
Join Date: Jan 2006
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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...
|
|

April 13th, 2006, 11:51 AM
|
|
Authorized User
|
|
Join Date: Mar 2006
Posts: 32
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|

April 13th, 2006, 05:23 PM
|
|
Authorized User
|
|
Join Date: Jan 2006
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hello-
That wont help, I need to check for specific files in the folder not return all of them. Thanks anyway
|
|

April 14th, 2006, 02:17 AM
|
|
Authorized User
|
|
Join Date: Mar 2006
Posts: 32
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|

April 14th, 2006, 09:59 PM
|
|
Friend of Wrox
|
|
Join Date: Jan 2004
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
|
|
;;;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
|
|
 |