查找分配给主驱动器的信函 [英] Find letter assigned to main drive
问题描述
我正在尝试找到像 Environ
这样的功能,以查找我的业务中的主驱动器在特定PC上映射到哪个驱动器。
I'm trying to find a function like Environ
to find what drive the main drive in my business has been mapped to on a particular PC.
使用文件路径G:\Eworking\SET\Operations\file我知道我的PC已被映射,以便该文件路径在G驱动器内,但其他可能被映射不同的是,我想确定它是什么。
Using the filepath "G:\Eworking\SET\Operations\file" I know that my PC has been mapped so that that filepath is within G drive but others may be mapped differently so I'd like to determine which it is.
我已经尝试了通过字母表的if else方法,并执行 if Dir([filepath])然后
之前(见下文),但我想知道是否有更好的方式这样做?
I've tried the if else method of going through the alphabet and doing a if Dir([filepath]) then
before (see below) but I was wondering if there's a better way of doing this?
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
推荐答案
A For ...使用ASCII字符的下一个循环似乎是合适的。
A For ... Next loop using the ASCII character seems appropriate.
dim c as integer
for c = 65 to 90
If CBool(Len(Dir(Chr(c) & sFilePath))) Then
msgbox "It's in drive " & Chr(c) '<~~msgbox, not magbox
exit for
end if
next c
if c > 90 then msgbox "never found"
这篇关于查找分配给主驱动器的信函的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!