"Jon Glazer" wrote in message
news:IW******** *************@f e2.columbus.rr. com...
: When doing a getfolder() I want the first file in the resulting FILES
: collection. I don't want to do a for/next cuz the list may be very long.
: Just the first file is all. How do I do this? Doin a
:
: Set objFile=Folder. Files(1) generates a Invalid procedure call or agument
: error.
Hi Jon...
This is what I came up with. It allows you to return the filename based on
an index value.
<%@ Language=VBScri pt %>
<%
Option Explicit
Response.Buffer = True
Function ShowFolderList( folderspec, index)
Dim fso, folder, file, s, i, d
i = 0
Set fso = CreateObject("S cripting.FileSy stemObject")
Set folder = fso.GetFolder(f olderspec)
Set d = CreateObject("S cripting.Dictio nary")
for each file in folder.Files
i = i + 1
s = file.name
d.Add i, s
Next
ShowFolderList = d.Item(index)
set fso = nothing
set folder = nothing
set d = nothing
End Function
Response.Write( ShowFolderList( "c:\inetpub\e", 1))
%>
If you just want it to always return the first one, you can shorten it to
this:
<%@ Language=VBScri pt %>
<%
Option Explicit
Response.Buffer = True
Function ShowFolderList( folderspec, index)
Dim fso, folder, file, s
Set fso = CreateObject("S cripting.FileSy stemObject")
Set folder = fso.GetFolder(f olderspec)
for each file in folder.Files
s = file.name
exit for
Next
ShowFolderList = s
set fso = nothing
set folder = nothing
End Function
Response.Write( ShowFolderList( "c:\inetpub\e") )
%>
HTH...
--
Roland Hall
/* This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose. */
Technet Script Center -
http://www.microsoft.com/technet/scriptcenter/
WSH 5.6 Documentation -
http://msdn.microsoft.com/downloads/list/webdev.asp
MSDN Library -
http://msdn.microsoft.com/library/default.asp