Solved

ShortpathName - GetDospath

Posted on 2003-12-01
4
208 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
Comment Utility
It works for me. Make sure he file does exist.
0
 

Author Comment

by:kamur
Comment Utility
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 100 total points
Comment Utility
>>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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
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…

743 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

16 Experts available now in Live!

Get 1:1 Help Now