Solved

ShortpathName - GetDospath

Posted on 2003-12-01
4
214 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 100 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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…
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…

910 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

23 Experts available now in Live!

Get 1:1 Help Now