Path in DOS format

A

Amjad

Hi,
How do you get the returned path from
FolderBrowserDialog.SelectedPath in DOS format (8-
characters-long folder names)?

That is:
If the returned path is: C:\Program Files\My Folders
I will get: C:\Progra~1\MyFold~1
 
H

Herfried K. Wagner [MVP]

* "Amjad said:
How do you get the returned path from
FolderBrowserDialog.SelectedPath in DOS format (8-
characters-long folder names)?

That is:
If the returned path is: C:\Program Files\My Folders
I will get: C:\Progra~1\MyFold~1

I am interested in the reason why you need that...
 
?

=?iso-8859-1?Q?Jos=E9_Manuel_Ag=FCero?=

Hi, Herfried:

Some people still need to shell a DOS based application... :'-(

The solution comes through the API function GetShortPathName: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/base/getshortpathname.asp.

Regards.


"Herfried K. Wagner [MVP]" <[email protected]> escribió en el mensaje | * "Amjad" <[email protected]> scripsit:
| > How do you get the returned path from
| > FolderBrowserDialog.SelectedPath in DOS format (8-
| > characters-long folder names)?
| >
| > That is:
| > If the returned path is: C:\Program Files\My Folders
| > I will get: C:\Progra~1\MyFold~1
|
| I am interested in the reason why you need that...
|
| --
| Herfried K. Wagner
| MVP · VB Classic, VB.NET
| <http://www.mvps.org/dotnet>
 
?

=?Windows-1252?Q?Jos=E9_Manuel_Ag=FCero?=

Problem solved?

Yes, but...

If someone likes something, somehow... managed, there is another solution:
Put a reference to Scripting type library in the project and create a FileSystemObject (see http://msdn.microsoft.com/library/d.../vbconintroductiontofilesystemobjectmodel.asp).
Now you can use the ShortPath Property of the "File" and "Folder" objects (see http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/jsproshortpath.asp).

Note (I say for Amjad, I'm sure you know, Herfried) that Scripting is part of the system automation model and is frecuently disabled for security reasons. Have it in mind if you want to distribute your application.

Regards.


"Herfried K. Wagner [MVP]" <[email protected]> escribió en el mensaje | * José Manuel Agüero <jmªgue®ø@v°daƒøne.e§> scripsit:
| > Some people still need to shell a DOS based application... :'-(
|
| Thanks, I didn't think of that...
|
| > The solution comes through the API function GetShortPathName:
| > http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/base/getshortpathname.asp.
|
| Problem solved?
|
| --
| Herfried K. Wagner
| MVP · VB Classic, VB.NET
| <http://www.mvps.org/dotnet>
 
A

Amjad

Thanks. You were right about the reason of why I'd need
the short path naming scheme in my program.

However, I tried the "GetShortPathName" function and VB
said it's not declared. How do I declare it?
Do you have a sample code on how to use this function in
VB .NET?

I'm trying to avoid using FileSystemObject option. I'm
looking for a simple string manipulation solution.

Amjad
-----Original Message-----

Yes, but...

If someone likes something, somehow... managed, there is another solution:
Put a reference to Scripting type library in the project
and create a FileSystemObject (see
http://msdn.microsoft.com/library/default.asp?
url=/library/en-
us/vbcn7/html/vbconintroductiontofilesystemobjectmodel.asp
).
Now you can use the ShortPath Property of the "File"
and "Folder" objects (see
http://msdn.microsoft.com/library/default.asp?
url=/library/en-us/script56/html/jsproshortpath.asp).
Note (I say for Amjad, I'm sure you know, Herfried) that
Scripting is part of the system automation model and is
frecuently disabled for security reasons. Have it in mind
if you want to distribute your application.
Regards.


"Herfried K. Wagner [MVP]" <[email protected]>
escribió en el mensaje 208219.news.uni-berlin.de...
 
?

=?iso-8859-1?Q?Jos=E9_Manuel_Ag=FCero?=

Hello, Amjad:

Here is an example written in two minutes:

class chema_gspn
declare auto function GetShortPathName lib "kernel32" (byval lpszLongPath as string, byval lpszShortPath as string, byval cchBuffer as integer) as integer
public shared sub Main()
dim result as new string(" "c,260) 'Needs to contain something.
call getshortpathname("C:\Documents and Settings\Chema\Mis documentos\Mis archivos recibidos", result, microsoft.visualbasic.len(result))
system.console.writeline(result.substring(0,result.indexof(char.minvalue))) 'Only get string until chr(0) found.
system.console.readline
end sub
end class


It's not perfect: "len" returns the number of characters, not the number of bytes, wich is what we need...; it has no error checking...; (put your own objections here)...

Regards.


"Amjad" <[email protected]> escribió en el mensaje Thanks. You were right about the reason of why I'd need
the short path naming scheme in my program.

However, I tried the "GetShortPathName" function and VB
said it's not declared. How do I declare it?
Do you have a sample code on how to use this function in
VB .NET?

I'm trying to avoid using FileSystemObject option. I'm
looking for a simple string manipulation solution.

Amjad
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top