Board index » Visual Studio » Short Path Name

Short Path Name

Visual Studio47
How do I convert the long path name format to a short

path name format?



Ex. How do I convert: C:\Program Files\My Folders

to: C:\Progra~1\MyFold~1



PS. I use VB .NET


-
 

Re:Short Path Name

"Amjad" <amjadfarran@hotmail.com>wrote in message

. . .

Quote
Ex. How do I convert: C:\Program Files\My Folders

to: C:\Progra~1\MyFold~1



Why would you need to?



Quote
PS. I use VB .NET



Why would you need to?



Regards,

Phill W.





-

Re:Short Path Name

I use an external program that accepts short names only

as parameters.



Do you know how to convert long path names to short ones

(8 characters) in VB .NET ?



Amjad



Quote
-----Original Message-----

"Amjad" <amjadfarran@hotmail.com>wrote in message

news:094801c39890$e4196d10$a601280a@phx.gbl...

.. . .

>Ex. How do I convert: C:\Program Files\My Folders

>to: C:\Progra~1\MyFold~1



Why would you need to?



>PS. I use VB .NET



Why would you need to?



Regards,

Phill W.





.



-

Re:Short Path Name

I wrote code to do it in VB6, but not VB.Net (uses API though, so you may be

able to convert it), I've posted it below for you.



'Module code



'General Declarations

Declare Function GetShortPathName Lib "kernel32" Alias "GetShortPathNameA"

(ByVal lpszLongPath As String, ByVal lpszShortPath As String, ByVal

cchBuffer As Long) As Long



Public Function GetDosPath(LPath As String) As String

Dim s As String, i As Long, PLen As Long

i = Len(LPath) + 1

s = String(i, 0)

PLen = GetShortPathName(LPath, s, i)

GetDosPath = Left$(s, PLen)

End Function



Usage:



Private Sub Command1_Click()

Text1.Text = GetDosPath(App.Path)

End sub



--

Regards



Steven Burn

Ur I.T. Mate Group CEO

www.it-mate.co.uk



Disclaimer:

I know I'm probably wrong, I just like taking part :o)





Amjad <amjadfarran@hotmail.com>wrote in message

Quote
I use an external program that accepts short names only

as parameters.



Do you know how to convert long path names to short ones

(8 characters) in VB .NET ?



Amjad



>-----Original Message-----

>"Amjad" <amjadfarran@hotmail.com>wrote in message

>news:094801c39890$e4196d10$a601280a@phx.gbl...

>.. . .

>>Ex. How do I convert: C:\Program Files\My Folders

>>to: C:\Progra~1\MyFold~1

>

>Why would you need to?

>

>>PS. I use VB .NET

>

>Why would you need to?

>

>Regards,

>Phill W.

>

>

>.

>





-

Re:Short Path Name

Your best bet is to ask in a .NET forum (forums with *dotnet* in them).

If this 'external program' requires a short file name, I'm guessing it's a

non-dotnet application (COM?) in which case, you are probably resigned to

using the API to generate a short file name from the long filename: using an

API call may have repercussions for your .net application (i.e. unmanaged

code).



SJW



"Amjad" <amjadfarran@hotmail.com>wrote in message

Quote
I use an external program that accepts short names only

as parameters.



Do you know how to convert long path names to short ones

(8 characters) in VB .NET ?



Amjad



>-----Original Message-----

>"Amjad" <amjadfarran@hotmail.com>wrote in message

>news:094801c39890$e4196d10$a601280a@phx.gbl...

>.. . .

>>Ex. How do I convert: C:\Program Files\My Folders

>>to: C:\Progra~1\MyFold~1

>

>Why would you need to?

>

>>PS. I use VB .NET

>

>Why would you need to?

>

>Regards,

>Phill W.

>

>

>.

>





-

Re:Short Path Name

I'm going to get my fingers chopped off for suggesting this.



The FileSystemObject will take care of this task, but I don't know if it

works in that new fangled dot Net thingy stuff though.



This is straight out of the MSDN ...



Sub ShowShortPath(filespec)

Dim fs, f, s

Set fs = CreateObject("Scripting.FileSystemObject")

Set f = fs.GetFile(filespec)

s = "The short path for " & "" & UCase(f.Name)

s = s & "" & vbCrLf

s = s & "is: " & "" & f.ShortPath & ""

MsgBox s, 0, "Short Path Info"



End Sub



(Fso rocks ... sometimes)



Regards



Steven Vine





"Amjad" <amjadfarran@hotmail.com>wrote in message

Quote
I use an external program that accepts short names only

as parameters.



Do you know how to convert long path names to short ones

(8 characters) in VB .NET ?



Amjad



>-----Original Message-----

>"Amjad" <amjadfarran@hotmail.com>wrote in message

>news:094801c39890$e4196d10$a601280a@phx.gbl...

>.. . .

>>Ex. How do I convert: C:\Program Files\My Folders

>>to: C:\Progra~1\MyFold~1

>

>Why would you need to?

>

>>PS. I use VB .NET

>

>Why would you need to?

>

>Regards,

>Phill W.

>

>

>.

>





-

Re:Short Path Name

On Wed, 22 Oct 2003 04:37:36 -0700, "Amjad" <amjadfarran@hotmail.com>wrote:



¤ How do I convert the long path name format to a short

¤ path name format?

¤

¤ Ex. How do I convert: C:\Program Files\My Folders

¤ to: C:\Progra~1\MyFold~1

¤

¤ PS. I use VB .NET



You can use the API function call previously mentioned:





Declare Function GetShortPathName Lib "kernel32" _

Alias "GetShortPathNameA" (ByVal lpszLongPath As String, _

ByVal lpszShortPath As String, ByVal cchBuffer As Int32) As Int32



Public Function GetShortName(ByVal LongFileName As String) As String

Dim RetVal As Int32, ShortPathName As String, PathNameLen As Integer

'Set up buffer area for API function call return

ShortPathName = Space(255)

PathNameLen = Len(ShortPathName)



RetVal = GetShortPathName(LongFileName, ShortPathName, PathNameLen)

'Strip away unwanted characters.

GetShortName = Left(ShortPathName, RetVal)

End Function





'Call to function

Dim ShortPathName As String

ShortPathName = GetShortName("C:\Program Files\Outlook Express\oemig50.exe")





Other than the variable type name change from Long to Int32 there is no difference in the code from

VB 6.0 to VB.NET.





Paul ~~~ pclement@ameritech.net

Microsoft MVP (Visual Basic)

-

Re:Short Path Name

Hello, group:



Note that under .NET you must change "Long" to "Integer" in the API =

declarations (in .NET an integer is 32 bits and a long is 64 bits).



Regards.





"Steven Burn" <ceo@PVT_it-mate.co.uk>escribi=F3 en el mensaje =

| I wrote code to do it in VB6, but not VB.Net (uses API though, so you =

may be

| able to convert it), I've posted it below for you.

|=20

| 'Module code

|=20

| 'General Declarations

| Declare Function GetShortPathName Lib "kernel32" Alias =

"GetShortPathNameA"

| (ByVal lpszLongPath As String, ByVal lpszShortPath As String, ByVal

| cchBuffer As Long) As Long

|=20

| Public Function GetDosPath(LPath As String) As String

| Dim s As String, i As Long, PLen As Long

| i =3D Len(LPath) + 1

| s =3D String(i, 0)

| PLen =3D GetShortPathName(LPath, s, i)

| GetDosPath =3D Left$(s, PLen)

| End Function

|=20

| Usage:

|=20

| Private Sub Command1_Click()

| Text1.Text =3D GetDosPath(App.Path)

| End sub

|=20

| --

| Regards

|=20

| Steven Burn

| Ur I.T. Mate Group CEO

| www.it-mate.co.uk

|=20

| Disclaimer:

| I know I'm probably wrong, I just like taking part :o)

|=20

|=20

| Amjad <amjadfarran@hotmail.com>wrote in message

| news:0b5301c39897$41bd8950$a401280a@phx.gbl...

|>I use an external program that accepts short names only

|>as parameters.

|>

|>Do you know how to convert long path names to short ones

|>(8 characters) in VB .NET ?

|>

|>Amjad

|>

|>>-----Original Message-----

|>>"Amjad" <amjadfarran@hotmail.com>wrote in message

|>>news:094801c39890$e4196d10$a601280a@phx.gbl...

|>>.. . .

|>>>Ex. How do I convert: C:\Program Files\My Folders

|>>>to: C:\Progra~1\MyFold~1

|>>

|>>Why would you need to?

|>>

|>>>PS. I use VB .NET

|>>

|>>Why would you need to?

|>>

|>>Regards,

|>>Phill W.

|>>

|>>

|>>.

|>>

|=20

|

-

Re:Short Path Name

Quote
Note that under .NET you must change.....



the group you're posting to. This is a VB "Classic" group. VB.Net q/a's belong in groups

that contain "dotnet" in their names.



--

Ken Halter - MS-MVP-VB - www.vbsight.com">www.vbsight.com

Please keep it in the groups..



"José Manuel Agüero" <jmªgue®ø@v°da?øne.e§>wrote in message

Hello, group:



Note that under .NET you must change "Long" to "Integer" in the API declarations (in .NET

an integer is 32 bits and a long is 64 bits).



Regards.





"Steven Burn" <ceo@PVT_it-mate.co.uk>escribió en el mensaje

| I wrote code to do it in VB6, but not VB.Net (uses API though, so you may be

| able to convert it), I've posted it below for you.

|

| 'Module code

|

| 'General Declarations

| Declare Function GetShortPathName Lib "kernel32" Alias "GetShortPathNameA"

| (ByVal lpszLongPath As String, ByVal lpszShortPath As String, ByVal

| cchBuffer As Long) As Long

|

| Public Function GetDosPath(LPath As String) As String

| Dim s As String, i As Long, PLen As Long

| i = Len(LPath) + 1

| s = String(i, 0)

| PLen = GetShortPathName(LPath, s, i)

| GetDosPath = Left$(s, PLen)

| End Function

|

| Usage:

|

| Private Sub Command1_Click()

| Text1.Text = GetDosPath(App.Path)

| End sub

|

| --

| Regards

|

| Steven Burn

| Ur I.T. Mate Group CEO

| www.it-mate.co.uk

|

| Disclaimer:

| I know I'm probably wrong, I just like taking part :o)

|

|

| Amjad <amjadfarran@hotmail.com>wrote in message

| news:0b5301c39897$41bd8950$a401280a@phx.gbl...

|>I use an external program that accepts short names only

|>as parameters.

|>

|>Do you know how to convert long path names to short ones

|>(8 characters) in VB .NET ?

|>

|>Amjad

|>

|>>-----Original Message-----

|>>"Amjad" <amjadfarran@hotmail.com>wrote in message

|>>news:094801c39890$e4196d10$a601280a@phx.gbl...

|>>.. . .

|>>>Ex. How do I convert: C:\Program Files\My Folders

|>>>to: C:\Progra~1\MyFold~1

|>>

|>>Why would you need to?

|>>

|>>>PS. I use VB .NET

|>>

|>>Why would you need to?

|>>

|>>Regards,

|>>Phill W.

|>>

|>>

|>>.

|>>

|

|





-

Re:Short Path Name

Hello, Ken:



I know, but Amjad said he uses VB.NET.



Regards.





"Ken Halter" <Ken_Halter@Use_Sparingly_Hotmail.com>escribi=F3 en el =

mensaje news:Og%23ca$MmDHA.2964@tk2msftngp13.phx.gbl...

|>Note that under .NET you must change.....

|=20

| the group you're posting to. This is a VB "Classic" group. VB.Net =

q/a's belong in groups

| that contain "dotnet" in their names.

|=20

| --=20

| Ken Halter - MS-MVP-VB - www.vbsight.com">www.vbsight.com

| Please keep it in the groups..

|=20

| "Jos=E9 Manuel Ag=FCero" <jm=AAgue=AE=F8@v=B0da=83=F8ne.e=A7>wrote in =

message

| news:u1rvTnMmDHA.1960@TK2MSFTNGP12.phx.gbl...

| Hello, group:

|=20

| Note that under .NET you must change "Long" to "Integer" in the API =

declarations (in .NET

| an integer is 32 bits and a long is 64 bits).

|=20

| Regards.

|=20

|=20

| "Steven Burn" <ceo@PVT_it-mate.co.uk>escribi=F3 en el mensaje

| news:ukRqOvJmDHA.1740@TK2MSFTNGP12.phx.gbl...

| | I wrote code to do it in VB6, but not VB.Net (uses API though, so =

you may be

| | able to convert it), I've posted it below for you.

| |

| | 'Module code

| |

| | 'General Declarations

| | Declare Function GetShortPathName Lib "kernel32" Alias =

"GetShortPathNameA"

| | (ByVal lpszLongPath As String, ByVal lpszShortPath As String, ByVal

| | cchBuffer As Long) As Long

| |

| | Public Function GetDosPath(LPath As String) As String

| | Dim s As String, i As Long, PLen As Long

| | i =3D Len(LPath) + 1

| | s =3D String(i, 0)

| | PLen =3D GetShortPathName(LPath, s, i)

| | GetDosPath =3D Left$(s, PLen)

| | End Function

| |

| | Usage:

| |

| | Private Sub Command1_Click()

| | Text1.Text =3D GetDosPath(App.Path)

| | End sub

| |

| | --

| | Regards

| |

| | Steven Burn

| | Ur I.T. Mate Group CEO

| | www.it-mate.co.uk

| |

| | Disclaimer:

| | I know I'm probably wrong, I just like taking part :o)

| |

| |

| | Amjad <amjadfarran@hotmail.com>wrote in message

| | news:0b5301c39897$41bd8950$a401280a@phx.gbl...

| |>I use an external program that accepts short names only

| |>as parameters.

| |>

| |>Do you know how to convert long path names to short ones

| |>(8 characters) in VB .NET ?

| |>

| |>Amjad

| |>

| |>>-----Original Message-----

| |>>"Amjad" <amjadfarran@hotmail.com>wrote in message

| |>>news:094801c39890$e4196d10$a601280a@phx.gbl...

| |>>.. . .

| |>>>Ex. How do I convert: C:\Program Files\My Folders

| |>>>to: C:\Progra~1\MyFold~1

| |>>

| |>>Why would you need to?

| |>>

| |>>>PS. I use VB .NET

| |>>

| |>>Why would you need to?

| |>>

| |>>Regards,

| |>>Phill W.

| |>>

| |>>

| |>>.

| |>>

| |

| |

|=20

|

-

Re:Short Path Name

SteveVine wrote:



[SNIP]



Quote
(Fso rocks ... sometimes)



As in, if you attach it to your application, it is quite likely to sink to

the bottom?





--

Regards,



Michael Cole





-

Re:Short Path Name

Lol





"Michael Cole" <michael.cole@hansen.com.invalid>wrote in message

Quote
SteveVine wrote:



[SNIP]



>(Fso rocks ... sometimes)



As in, if you attach it to your application, it is quite likely to sink to

the bottom?





--

Regards,



Michael Cole









-