2

我正在使用此代码来获取目录的子文件夹:

Dim fo As Scripting.Folder
Set fo = fso.GetFolder(m_sFolder)

Dim nSubfolder As Scripting.Folder

For Each nSubfolder In fo.SubFolders

    Debug.Print "Folder " & fo.Path & " has subfolder " & nSubfolder 

Next

现在当 m_sFolder 为“C:\Users\MyUser\Documents”时,一个子文件夹为“C:\Users\MyUser\Documents\Eigene Bilder”。“Eigene Bilder”是 Windows 将德语文件夹称为“我的图片”。

但是,文件夹“C:\Users\MyUser\Documents”不包含“我的图片”、“图片”或“Eigene Bilder”。

文件夹“我的图片”位于:C:\Users\MyUser\Pictures

谁能告诉我为什么 FSO 可能想告诉我这个目录“C:\Users\MyUser\Documents\Eigene Bilder”存在吗?

我完全感到困惑。

4

2 回答 2

3

它不是一个目录,它是一个连接(或重解析)点,就像重定向到文件系统级别的另一个位置。

dir "C:\Users\MyUser\Documents\" /ad

从命令行将列出这些带有<JUNCTION>标签(而不是<DIR>)。

无需使用 FSO,内置文件系统函数将不包括这些:

Dim path As String: path = "C:\Users\MyUser\Documents\"
Dim dirn As String

dirn = Dir$(path, vbDirectory)

Do While dirn <> ""
    If (GetAttr(path & dirn) And vbDirectory) = vbDirectory And dirn <> "." And dirn <> ".." Then
        Debug.Print path & dirn
    End If
    dirn = Dir$()
Loop
于 2017-01-24T18:20:01.733 回答
1

如果您坚持使用 FSO,您需要了解这些事项。此示例试图了解,并且应该为您提供处理此问题所需的信息:

Const ssfPERSONAL = 5
Const FILE_ATTRIBUTE_REPARSE_POINT = &H400&
Dim TargetFolderPath As String
Dim SubFolder As Scripting.Folder
Dim SubFile As Scripting.File

'Don't early-bind to Shell32 objects, Microsoft has failed
'to maintain binary compatibility across Windows versions:
TargetFolderPath = CreateObject("Shell.Application").NameSpace(ssfPERSONAL).Self.Path
Debug.Print TargetFolderPath
With New Scripting.FileSystemObject
    With .GetFolder(TargetFolderPath)
        For Each SubFolder In .SubFolders
            With SubFolder
                Debug.Print .Name;
                Debug.Print " ["; .Type;
                If .Attributes And FILE_ATTRIBUTE_REPARSE_POINT Then
                    Debug.Print ", reparse point";
                End If
                Debug.Print "]"
            End With
        Next
        For Each SubFile In .Files
            With SubFile
                Debug.Print .Name; " ["; .Type; "]"
            End With
        Next
    End With
End With
于 2017-01-24T21:20:04.670 回答