items, collections - filesystemobject...

  • Thread starter Thread starter curtis m. west
  • Start date Start date
C

curtis m. west

hi NG

sorry for this maybe stupid question:
i have this construction:
----->>>> CUT ON <<<<<-----
Dim objFso As Object
Dim objFolder As Object
Dim objFile As Object

objFso = CreateObject("Scripting.FileSystemObject")
objFolder = objFso.GetFolder("<mypath>")
For Each objFile In objFolder.Files
Console.WriteLine(objFile.Name)
Next
objFile = Nothing
objFolder = Nothing
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 item?

my guess would be anything like:
objFile = objFolder.Files.Item(1)
objFile = objFolder.Files(1)
objFile = objFolder.Files[1]
instead of the "for each next"-construction...
but - no success yet... :(

thanks for a short feedback
greetz, curtis
 
Hi,

Take a look at the classes in the system.io namespace. Especially
the directoryinfo and fileinfo classes.

Dim di As New System.IO.DirectoryInfo("C:\")

For Each fiCur As System.IO.FileInfo In di.GetFiles

Trace.WriteLine(fiCur.Name)

Next fiCur



Ken

---------------------

hi NG

sorry for this maybe stupid question:
i have this construction:
----->>>> CUT ON <<<<<-----
Dim objFso As Object
Dim objFolder As Object
Dim objFile As Object

objFso = CreateObject("Scripting.FileSystemObject")
objFolder = objFso.GetFolder("<mypath>")
For Each objFile In objFolder.Files
Console.WriteLine(objFile.Name)
Next
objFile = Nothing
objFolder = Nothing
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 item?

my guess would be anything like:
objFile = objFolder.Files.Item(1)
objFile = objFolder.Files(1)
objFile = objFolder.Files[1]
instead of the "for each next"-construction...
but - no success yet... :(

thanks for a short feedback
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

Back
Top