使用*而不是整个文件夹名称打开文件夹

时间:2014-04-03 07:52:54

标签: vba ms-access access-vba ms-access-2010

我想通过不使用整个foldername来打开文件夹。

Foldername是219448_CustomerName

但我不知道客户名称,所以我只想在最后使用号码219448和*。

这可能吗?

我这样使用它,但它不起作用。

Call Shell("explorer.exe" & " " & "G:\Money\Credit Assessment\Customer\219448*", vbNormalFocus)

如果我这样运行,资源管理器只是打开“MyDocuments”。

我还想在明星后面添加另一个文件夹,以便更深入:

Call Shell("explorer.exe" & " " & "G:\Money\Credit Assessment\Customer\219448*\Info", vbNormalFocus)

1 个答案:

答案 0 :(得分:2)

shell不支持通配符表示目录名称的路径。

这样的路径可以有多个通配符匹配,那么explorer.exe会对50个不同的路径做什么?

如果您想要实际执行此操作,则需要从通配符手动定位具体路径并将其传递给资源管理器。

示例:

'wildcard must be in the last path-part, no trailing \
inputPath = "G:\Money\Credit Assessment\Customer\219448*"

'get fixed path
fixedPath = Left$(inputPath, InStrRev(inputPath, "\"))
'wildcard part
wildPath = Mid$(inputPath, InStrRev(inputPath, "\") + 1)

'//loop fixed path looking for a wildcard match on subdirs
aDir = Dir$(fixedPath & "*.*", vbDirectory)
Do While Len(aDir)
    If aDir <> "." And aDir <> ".." And GetAttr(fixedPath & aDir) And vbDirectory Then
        If aDir Like wildPath Then
            MsgBox "found: " & fixedPath & aDir
        End If
    End If

    aDir = Dir$()
Loop
相关问题