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.

Can anyone help?

Thanks!

Re: All i want is the first file by Curt_C

Curt_C
Thu Oct 07 15:56:10 CDT 2004

problem may be that the "first" isn't really defined.
Anyway, do a simple loop till i = 1


--
Curt Christianson
Owner/Lead Developer, DF-Software
Site: http://www.Darkfalz.com
Blog: http://blog.Darkfalz.com


"Jon Glazer" <jglazer.delete.me@adconn.com> wrote in message
news:IWh9d.254916$787.122604@fe2.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.
>
> Can anyone help?
>
> Thanks!
>
>



Re: All i want is the first file by Roland

Roland
Fri Oct 08 03:29:25 CDT 2004

"Jon Glazer" wrote in message
news:IWh9d.254916$787.122604@fe2.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=VBScript %>
<%
Option Explicit
Response.Buffer = True

Function ShowFolderList(folderspec, index)
Dim fso, folder, file, s, i, d
i = 0
Set fso = CreateObject("Scripting.FileSystemObject")
Set folder = fso.GetFolder(folderspec)
Set d = CreateObject("Scripting.Dictionary")
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=VBScript %>
<%
Option Explicit
Response.Buffer = True

Function ShowFolderList(folderspec, index)
Dim fso, folder, file, s
Set fso = CreateObject("Scripting.FileSystemObject")
Set folder = fso.GetFolder(folderspec)
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