Solved

expand short file name to long

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Share codes 68 115
vb6 programatically bring window to front 8 53
How does CurrentUser work? 10 26
Spell Check in VB6 13 52
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 Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

747 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now