for each...next...objects, collections?!

C

curtis m. west

hi NG

sorry for this maybe stupid question:
i have this construction:
----->>>> CUT ON <<<<<-----
Set objFso = Server.CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder("<mypath>")
For Each objFile in objFolder.Files
response.write(objFile.Name&"<br>")
next
set objFolder = nothing
set objFSO = nothing
----->>>>> CUT OFF <<<<<----

so far, so good. but how can i get only
ONE filename - only the name of the
"first" file. i don't care about a special
order.

"Files" seems to be a collection
of "file-objects", so how can i
access only one?

my guess would be anything like:
set objFile = objFolder.Files
set objFile = objFolder.Files[1]
instead of the "for each next"-construction...


thanks for a short feedback
greetz, curtis
 
B

Bob Barrows [MVP]

curtis said:
hi NG

sorry for this maybe stupid question:
i have this construction:
----->>>> CUT ON <<<<<-----
Set objFso = Server.CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder("<mypath>")
For Each objFile in objFolder.Files
response.write(objFile.Name&"<br>")
next
set objFolder = nothing
set objFSO = nothing
----->>>>> CUT OFF <<<<<----

so far, so good. but how can i get only
ONE filename - only the name of the
"first" file. i don't care about a special
order.

"Files" seems to be a collection
of "file-objects", so how can i
access only one?

my guess would be anything like:
set objFile = objFolder.Files
set objFile = objFolder.Files[1]
instead of the "for each next"-construction...
No. The Files collection does not support the numeric index property the way
most collections do.

Here is the scripting documentation:
http://tinyurl.com/7rk6

Look for the filesystemobject methods. I think there's one called getfile
but I'm too lazy to look it up right now.

Bob Barrows
 
C

curtis m. west

curtis said:
hi NG

sorry for this maybe stupid question:
i have this construction:
----->>>> CUT ON <<<<<-----
Set objFso = Server.CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder("<mypath>")
For Each objFile in objFolder.Files
response.write(objFile.Name&"<br>")
next
set objFolder = nothing
set objFSO = nothing
----->>>>> CUT OFF <<<<<----

so far, so good. but how can i get only
ONE filename - only the name of the
"first" file. i don't care about a special
order.

"Files" seems to be a collection
of "file-objects", so how can i
access only one?

my guess would be anything like:
set objFile = objFolder.Files
set objFile = objFolder.Files[1]
instead of the "for each next"-construction...
No. The Files collection does not support the numeric index property the
way most collections do.

Here is the scripting documentation:
http://tinyurl.com/7rk6

Look for the filesystemobject methods. I think there's one called getfile
but I'm too lazy to look it up right now.

thank you very much - cool documentation.
i already tried the "getFile"-method...
....but since this method needs a filename
it's of no use for me.
i also tried

objFso.GetFile("<mpath>\*")

still no luck...
any other ideas?

thanks for any help
greetz, curtis
 
B

Bob Barrows [MVP]

curtis said:
curtis said:
hi NG

sorry for this maybe stupid question:
i have this construction:
----->>>> CUT ON <<<<<-----
Set objFso = Server.CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder("<mypath>")
For Each objFile in objFolder.Files
response.write(objFile.Name&"<br>")
next
set objFolder = nothing
set objFSO = nothing
----->>>>> CUT OFF <<<<<----

so far, so good. but how can i get only
ONE filename - only the name of the
"first" file. i don't care about a special
order.

"Files" seems to be a collection
of "file-objects", so how can i
access only one?

my guess would be anything like:
set objFile = objFolder.Files
set objFile = objFolder.Files[1]
instead of the "for each next"-construction...
No. The Files collection does not support the numeric index property
the way most collections do.

Here is the scripting documentation:
http://tinyurl.com/7rk6

Look for the filesystemobject methods. I think there's one called
getfile but I'm too lazy to look it up right now.

thank you very much - cool documentation.
i already tried the "getFile"-method...
...but since this method needs a filename
it's of no use for me.
i also tried

objFso.GetFile("<mpath>\*")

still no luck...
any other ideas?

thanks for any help
greetz, curtis

Use Exit For in your loop

For Each objFile in objFolder.Files
response.write(objFile.Name&"<br>")
Exit For
next
 
E

Egbert Nierop \(MVP for IIS\)

curtis m. west said:
thank you very much - cool documentation.
i already tried the "getFile"-method...
...but since this method needs a filename
it's of no use for me.
i also tried

objFso.GetFile("<mpath>\*")

still no luck...
any other ideas?

Hi,

You know, windows does not 'know' or define what is your first file for a
folder, based on what? On creation/modification/name/extensions etc.
So you SHOULD get all files, sort them, and then pick your first file...

Regards,
 
C

curtis m. west

Egbert Nierop (MVP for IIS) said:
Hi,

You know, windows does not 'know' or define what is your first file for a
folder, based on what? On creation/modification/name/extensions etc.
So you SHOULD get all files, sort them, and then pick your first file...

again, i don't care about an order,
as i have to proccess every file anyway...

....hmm... when using

for each
next

there is a kind of "first" result...
....and this would be ok (therefore i am using
the proposed "exit for" statement now)

i do "bulk-proccessing" of digital pictures,
and as processing one image takes
about 10 seconds, i have a problem
with the script-timeout when processing
lots of images...

so i use the workaround, that i
process one image a time and then
refresh the page using the meta refresh-statement...
another benefit from this method:
i can show some progress-information to the user.

greetz, curtis
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,540
Members
45,025
Latest member
KetoRushACVFitness

Latest Threads

Top