Solved

expand short file name to long

Posted on 2004-08-04
5
488 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

733 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