get file full path (1 Viewer)

revlisj

Registered User.
Local time
Today, 10:49
Joined
Jun 11, 2013
Messages
29
Greetings,

I’m trying to programmatically (without any user intervention) retrieve the “long path name” for a given file. It seems to me this should be a rather easy thing to achieve using Access VBA. I’ve tried using various FileSystemObject methods with no luck. I’ve Googled many variants of “VBA get full path” without any meaningful hits.

I’m hoping to provide the first string as a parameter to some object and have it magically return the second string.

String 1: C:\PROGRA~2\COMMON~1\MICROS~1\VBA\VBA7\VBE7.DLL

Stint 2: C:\Program Files (x86)\Common Files\microsoft shared\VBA\VBA7

Am I missing something very obvious?

Cheers
 

llkhoutx

Registered User.
Local time
Today, 09:49
Joined
Feb 26, 2001
Messages
4,018
Where does the "String 1" value come from?
 

revlisj

Registered User.
Local time
Today, 10:49
Joined
Jun 11, 2013
Messages
29
It comes from another function that only returns a "short" path name. I need the "long" path equivalent.

Cheers
 

CJ_London

Super Moderator
Staff member
Local time
Today, 15:49
Joined
Feb 19, 2013
Messages
16,685
It comes from another function that only returns a "short" path name.
why not modify that function to return the full path?

However I would suggest a basic principle would be to

split the path on "\" into an array

from the top rebuild the path using the dir function - I'm not sure but I believe the number after the tilde (~) indicates the position of folder e.g.

C:\Program Files...........will equate to C:\PROGRA~1
C:\Program Files (x86)..will equate to C:\PROGRA~2
 

revlisj

Registered User.
Local time
Today, 10:49
Joined
Jun 11, 2013
Messages
29
Thanks, it's a Microsoft function, I cannot change the returned values. Sorry, I should have included the subroutine straight away (see below). "Ref.FullPath" is a bit misleading. It actually returns "short" path names. I need "long" path names.

Sub GetReferences() 'get VBA references
Dim Ref As Reference
Dim Msg

For Each Ref In Access.References
Msg = "VBA Reference Name = " & Ref.Name & vbTab & vbTab & _
"Path = " & Ref.FullPath & vbTab & vbTab & _
"Version = " & Ref.Major & "." & Ref.Minor & vbTab & vbTab
If Ref.IsBroken Then
Msg = Msg & "* MISSING reference *"
End If

Debug.Print Msg
Next Ref

End Sub
 

CJ_London

Super Moderator
Staff member
Local time
Today, 15:49
Joined
Feb 19, 2013
Messages
16,685
well I've given you a suggestion tor try in my previous post
 

PeterF

Registered User.
Local time
Today, 16:49
Joined
Jun 6, 2006
Messages
295
The dir function as CJ_London suggested is the way to go but dir returns the short folder / filename if the input is the short variant use dir$ instead.
This is a sample I found long time ago.

Code:
Function GetLongPath(ShortPath As String) As String
'convert short DOS 8.3 style filename to long NTFS filename and doesn't compalain when input is long filename.
'found this code on http://www.xtremevbtalk.com/showthread.php?t=286071
Dim LongPath As String, Sep As Integer
    Do While Len(ShortPath) > 0
        LongPath = Dir$(ShortPath, vbHidden + vbDirectory) & "\" & LongPath 'need vbHidden to find hidden files or folders
        Sep = InStrRev(ShortPath, "\") - 1
        If Sep <= 3 Then
            LongPath = Left(ShortPath, 2) & "\" & LongPath
            Exit Do
        Else
            ShortPath = Left(ShortPath, Sep)
        End If
    Loop
    GetLongPath = LongPath
End Function
 

revlisj

Registered User.
Local time
Today, 10:49
Joined
Jun 11, 2013
Messages
29
Thanks Peter! Your GetLongPath function did the trick.
 

Users who are viewing this thread

Top Bottom