Solved

ShortpathName - GetDospath

Posted on 2003-12-01
4
217 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Suggested Solutions

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…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…

726 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