|
-
April 16th, 2003, 07:57 PM
#1
Long filenames converting to short ones (with ~1)
Hello.
I'm making a frontend program that uses emulators to play games.
I have to use one that doesn't accept long filenames though...
How can I convert the whole path of a file to the same path written the short way?
(for example C:\Program files\test.txt --> C:\Progra~1\test.txt)
I don't want to use the first 6 characters of the filename and then add ~1 because it can be ~2 if you have 2 files with the same 6 first characters. And it doesn't have to do with sorting...
I think I should first check if there's a ??????~2.??? file. If not, then I know that the filename is ??????~1.???
What can I do when there are many?
Visit www.greekroms.net
Greek translations of roms
-
April 16th, 2003, 08:03 PM
#2
There is the GetShortPathName API for that.
Please remember to rate the posts and threads that you find useful.
How can something be both new and improved at the same time?
-
April 16th, 2003, 10:06 PM
#3
Visit www.greekroms.net
Greek translations of roms
-
April 17th, 2003, 06:37 PM
#4
hi wizbang
can u give me an example to use this function
i need to get short file name for
C:\Program Files\Internet Explorer\Connection Wizard\Readme.txt
what parameter should i pass
thanx
-
April 17th, 2003, 07:34 PM
#5
You can get all the info for tons of API's at allapi.net. Get both the guide and viewer. They are a MUST HAVE!!
Please remember to rate the posts and threads that you find useful.
How can something be both new and improved at the same time?
-
April 18th, 2003, 02:04 AM
#6
From Api-guide
(Api guide is a free tool you can download at www.allapi.net)
Code:
Private Declare Function GetShortPathName Lib "kernel32" Alias "GetShortPathNameA" (ByVal lpszLongPath As String, ByVal lpszShortPath As String, ByVal lBuffer As Long) As Long
Public Function GetShortPath(strFileName As String) As String
'KPD-Team 1999
'URL: http://www.allapi.net/
'E-Mail: [email protected]
Dim lngRes As Long, strPath As String
'Create a buffer
strPath = String$(165, 0)
'retrieve the short pathname
lngRes = GetShortPathName(strFileName, strPath, 164)
'remove all unnecessary chr$(0)'s
GetShortPath = Left$(strPath, lngRes)
End Function
Private Sub Form_Load()
MsgBox GetShortPath("c:\Program Files\")
End Sub
Related function: getFullPathName:
Code:
Private Declare Function GetFullPathName Lib "kernel32" Alias "GetFullPathNameA" (ByVal lpFileName As String, ByVal nBufferLength As Long, ByVal lpBuffer As String, ByVal lpFilePart As String) As Long
Private Sub Form_Load()
'KPD-Team 2000
'URL: http://www.allapi.net/
'E-Mail: [email protected]
Dim Buffer As String, Ret As Long
'create a buffer
Buffer = Space(255)
'copy the current directory to the buffer and append 'myfile.ext'
Ret = GetFullPathName("myfile.ext", 255, Buffer, "")
'remove the unnecessary chr$(0)'s
Buffer = Left(Buffer, Ret)
'show the result
MsgBox Buffer
End Sub
...at present time, using mainly Net 4.0, Vs 2010
Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
all the other wonderful people who made and make Codeguru a great place.
Come back soon, you Gurus.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|