?
Solved

ShortpathName - GetDospath

Posted on 2003-12-01
4
Medium Priority
?
224 Views
Last Modified: 2008-02-01
Hello,

I am trying to get shortpathname like:

filepath = GetDosPath(filepat)
'where filepath = "Q:\NBS\NBSCORE\PPS\V101\TESTRES\SAPLIB\1EMFAB.DAT"

and,

Option Explicit

Declare Function GetShortPathName Lib "kernel32" Alias _
"GetShortPathNameA" (ByVal lpszLongPath As String, _
ByVal lpszShortPath As String, ByVal cchBuffer As Long) As Long

Public Function GetDosPath(LongPath As String) As String

Dim s As String
Dim i As Long
Dim PathLength As Long

        i = Len(LongPath) + 1

        s = String(i, 0)

        PathLength = GetShortPathName(LongPath, s, i)

        GetDosPath = Left$(s, PathLength)

End Function

This is not giving correct results...filepath variable comes as blanks after getdospath.

But the same thing works fine if the filepath is in local C:\ drive.

Any ideas
Kamur
0
Comment
Question by:kamur
  • 2
  • 2
4 Comments
 
LVL 26

Expert Comment

by:EDDYKT
ID: 9851286
It works for me. Make sure he file does exist.
0
 

Author Comment

by:kamur
ID: 9851755
The file exists..I can see that this line of code is giving all blanks,

s = String(i, 0)

For a shorter path length file, it gives correctly.,

Thanks
0
 
LVL 26

Accepted Solution

by:
EDDYKT earned 400 total points
ID: 9851799
>>s = String(i, 0)


This line is just preset the string to i length, it calls before the getshortpath


Again do

Public Function GetDosPath(LongPath As String) As String

Dim s As String
Dim i As Long
Dim PathLength As Long

if (dir(longpath) = "") then exit function  ' to check fhe file exists


        i = Len(LongPath) + 1

        s = String(i, 0)

        PathLength = GetShortPathName(LongPath, s, i)

        GetDosPath = Left$(s, PathLength)

End Function
0
 

Author Comment

by:kamur
ID: 9852260
You are right, Eddykt. The file exists, but then the filepat variable (longpath name) was getting populated wrongly from logic prior to this function. Longpath was returning,"Q:\NBS\NBSCORE\PPS\V101\TESTRES\SAPLIB1EMFAB.DAT"  with out the slash at the end.

I resolved it now. Thanks for the suggestion.
Regards
Kamur
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

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…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
Suggested Courses

864 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