Problem with Item() while trying to obtain subdirectory name

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am trying to get the names of all subdirectories in a folder. I am
encountering a problem when trying to get the name from the item(). Here is
what I am doing, and the error message I receive. Any suggestions on what I
am doing wrong?

Set fs = CreateObject("scripting.filesystemobject")
Set f = fs.GetFolder("C\")
Set subs = f.subfolders
MsgBox subs.Item(1).Name

The error I get is Run Time Error 5
Invalid procedure call or argument.

Thanks
 
I've noticed that there are certain types of collections where numeric
indices don't work. Apparently, Folders is one such collection. The
following, on the other hand, works:

For Each x In subs
MsgBox x.Name
Next x

--
Regards,

Tushar Mehta
www.tushar-mehta.com
Multi-disciplinary business expertise
+ Technology skills
= Optimal solution to your business problem
Recipient Microsoft MVP award 2000-2004
 
Back
Top