Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Extracting full path from drive letter 2

Status
Not open for further replies.

furtivevole

Technical User
Jun 21, 2001
84
GB
Hi
I'd like to be able to take a conventional letter-mapped path, say, "H:\SomeFolder\SomeFile.exe", and convert it into a full path, "\\MyServer\ParentFolder\SomeFolder\SomeFile.exe". This is so that an individual user with their own drive mappings can identify a file which (assuming permissions are OK) is accessible to anyone else. There should be no need to convert 8.3 format files into long format.

Can anyone offer some steerage on this please?
 
[tt]spath="H:\SomeFolder\SomeFile.exe"
sdriver="\\MyServer\ParentFolder"

apath=split(spath,":")
if ubound(apath)=1 then
spath2=sdriver & apath(1) 'desired result
else
wscript.echo "incorrect format of " & spath
'whatever need to define spath2
end if[/tt]
 
Thanks, Tsuji, but what I'm looking for is rather more than parsing the string. I have to deal with any user, any server drive and any potential drive mapping, so a hardcoded solution isn't appropriate here.

On W2K (havn't checked elsewhere so far) the server drives are held in the registry under HKCU\Network.
 
spath and sdriver are meant to be "dynamic" if you like the word. It is "hardcoded" only per your question. The rest is general. To dynamically determine spath and sdriver is beyond the face of the question asked originally. I leave other to do that part with your late statement.
 
Something like this may help you get closer...you should be able to follow most of it assuming you have some VBScript experience.

Code:
Option Explicit

GetDriveMappings()

Sub GetDriveMappings()
	Dim RegEx : Set RegEx = GetRegExp
	Dim objShell : Set objShell = CreateObject("WScript.Shell")
	Dim objExec : Set objExec = objShell.Exec("%comspec% /c NET USE")
	Dim colMatches : Set colMatches = RegEx.Execute(objExec.StdOut.ReadAll)
	Dim objMatch, strDriveLetter, strDrivePath
	For Each objMatch In colMatches
		strDriveLetter = objMatch.SubMatches(0)
		strDrivePath = objMatch.SubMatches(1)
		WScript.Echo strDriveLetter & vbTab & strDrivePath
	Next
End Sub

Function GetRegExp
	Dim RegEx : Set RegEx = New RegExp
	RegEx.Pattern = "\s+([A-Z]:)\s+(\\\\.+)\s+Microsoft"
	RegEx.IgnoreCase = True
	RegEx.Global = True
	Set GetRegExp = RegEx
End Function

--------------------------------------------------------------------------------
dm4ever
My philosophy: K.I.S.S - Keep It Simple Stupid
 
Why not simply use the WshNetwork.EnumNetworkDrives method ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
dm4ever, PH - thanks for your posts - much closer to what I'm after. Now need to play with both options!
 
Take a look at this thread:

thread222-1019804

Swi
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top