FSO返回不存在的子文件夹

时间:2017-01-24 18:02:17

标签: vb6 fso

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

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 \图片

有人可以告诉我为什么FSO可能想告诉我这个目录" C:\ Users \ MyUser \ Documents \ Eigene Bilder"存在?

我完全不知所措。

2 个答案:

答案 0 :(得分:3)

这不是一个目录它是Junction (or Reparse) Point,就像重定向到文件系统级别的另一个位置。

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

答案 1 :(得分: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