我正在尝试找到一个类似的函数Environ
查找我的业务中的主驱动器已映射到特定 PC 上的哪个驱动器。
使用文件路径“G:\Eworking\SET\Operations\file”我知道我的电脑已被映射,因此该文件路径位于 G 驱动器内,但其他文件路径可能会以不同的方式映射,因此我想确定它是什么。
我尝试过 if else 方法来遍历字母表并执行if Dir([filepath]) then
之前(见下文)但我想知道是否有更好的方法来做到这一点?
Sub LoopThroughDrives()
sFilePath As String
sFilePath = ":\Eworking\SET\Operations\file"
If Dir("A" & sFilePath) > 0 Then
msgbox ("It's in drive A")
Else
If Dir("B" & sFilePath) > 0 Then
msgbox ("It's in drive B")
Else
If Dir("C" & sFilePath) > 0 Then
msgbox ("It's in drive C")
Else
'...........................
'All other letters of the alphabet, checking each possibility
'...........................
End If
End If
End If
End Sub
您可以像这样获取驱动器号和路径:
For Each d In CreateObject("Scripting.FileSystemObject").Drives
Debug.Print d.DriveLetter, d.Path, d.ShareName
Next
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)