?
Solved

ShortpathName - GetDospath

Posted on 2003-12-01
4
Medium Priority
?
221 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 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

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…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

762 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