Solved

expand short file name to long

Posted on 2004-08-04
5
486 Views
Last Modified: 2012-08-13
When I call a function like Environ("TEMP"), I often get a result that looks like this "C:\DOCUME~1\..." instead of this: "c:\Documents and Settings\...".  Is there a way, in VB6, to translate from the short filename to the long?
0
Comment
Question by:dannykrouk
5 Comments
 
LVL 33

Expert Comment

by:sajuks
ID: 11723359
0
 
LVL 5

Accepted Solution

by:
ZenMasterrr earned 125 total points
ID: 11723961
sajuks

cant get that link to open,

so...

Public Function LongFileName(ByVal short_name As String) As _
    String
Dim pos As Integer
Dim result As String
Dim long_name As String

    ' Start after the drive letter if any.
    If Mid$(short_name, 2, 1) = ":" Then
        result = Left$(short_name, 2)
        pos = 3
    Else
        result = ""
        pos = 1
    End If

    ' Consider each section in the file name.
    Do While pos > 0
        ' Find the next \.
        pos = InStr(pos + 1, short_name, "\")

        ' Get the next piece of the path.
        If pos = 0 Then
            long_name = Dir$(short_name, vbNormal + _
                vbHidden + vbSystem + vbDirectory)
        Else
            long_name = Dir$(Left$(short_name, pos - 1), _
                vbNormal + vbHidden + vbSystem + _
                vbDirectory)
        End If
        result = result & "\" & long_name
    Loop

    LongFileName = result
End Function

danny, in case you didn't get that link to work :))
0
 
LVL 33

Expert Comment

by:sajuks
ID: 11724033
Opens ok in mine , just takes a long time for it to load fully.
0
 
LVL 26

Expert Comment

by:EDDYKT
ID: 11725037
Private Declare Function GetFullPathName Lib "kernel32" Alias "GetFullPathNameA" (ByVal lpFileName As String, ByVal nBufferLength As Long, ByVal lpBuffer As String, ByVal lpFilePart As String) As Long
Private Sub Form_Load()
    'KPD-Team 2000
    'URL: http://www.allapi.net/
    'E-Mail: KPDTeam@Allapi.net
    Dim Buffer As String, Ret As Long
    'create a buffer
    Buffer = Space(255)
    'copy the current directory to the buffer and append 'myfile.ext'
    Ret = GetFullPathName("myfile.ext", 255, Buffer, "")
    'remove the unnecessary chr$(0)'s
    Buffer = Left(Buffer, Ret)
    'show the result
    MsgBox Buffer
End Sub
0
 
LVL 11

Expert Comment

by:ajaikumarr
ID: 11725624
Hai,

Here is the code..

Private Declare Function GetLongPathName Lib "kernel32" Alias "GetLongPathNameA" (ByVal lpszShortPath As String, ByVal lpszLongPath As String, ByVal cchBuffer As Long) As Long

Const MAX_PATH = 260

' Convert a short file/path name to a long name the file or path must exist returns a null string in case of error
' IMPORTANT: this function is only available under Windows 98 and Windows 2000

Public Function LongPathName(ByVal FileName As String) As String
    Dim length As Long, res As String
    On Error Resume Next
   
    res = String$(MAX_PATH, 0)
    length = GetLongPathName(FileName, res, Len(res))
    If length And Err = 0 Then
        LongPathName = Left$(res, length)
    End If
End Function

Bye
Ajai
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Access 2003, my txt file export is running backwards 4 52
SSRS expression Issue finding a string 10 79
VBA error replacing data 6 40
Help me. 3 54
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question