How to get list of subfolders, including shortcuts to folders?

J

JoeU2004

The code below prints a list of subfolders in the specified folder.
However, it overlooks shortcuts to folders.

How can I include shortcuts to folders in the list, but not files and
shortcuts to files?

I think I want to know: how can I find the attribute of the object that a
shortcut ultimately links to?

(By "ultimately links to", I mean: the non-shortcut object, if a shortcut
links to a shortcut, if that is even possible in Win XP.)

Shortcuts to folders and files have only the attribute vbArchive on Win XP,
the same as normal files. (I suspect GetAttr returns zero if the object has
been backed up.)

Shortcuts are distinguishable from normal file by the extension ".lnk". But
shortcuts to folders seem indistinguishable from shortcuts to files.


Sub doit()
Const topdir As String = "C:\Documents and Settings\foo\My Documents\bar\"
Dim d As String, x As Long
d = Dir(topdir, vbDirectory)
While d <> ""
x = GetAttr(topdir & d)
If InStr(d, ".lnk") Then stop 'debug
If x And vbDirectory Then Debug.Print d
d = Dir()
Wend
End Sub
 
J

JoeU2004

Steve Yandl said:
Something like what I've got below is a slightly
different approach but should deliver close to
what you want.

Yes, it seems to do exactly what I want. Thanks.

I confess that I don't fully understand why.

I certainly understand the logic of VB code, taking some things for granted.
But I really have no knowledge of the Scripting.FileSystemObject and
WScript.Shell objects.

Where should I go to learn all about them?

(A Google search turned up some references, some more complete than others.
I have not fully explored this.)


----- original message -----
 

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

Top