Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Converting LFN to MS-DOS Names 1

Status
Not open for further replies.

AnnOminous

Programmer
Oct 1, 1999
9
US
Does anyone know a good way to convert long file names into the corresponding MS-DOS file names?<br>
Using the Dir function in VB6. Thank you for any help.<br>

 
I've never used the following function, but the originator<br>
claims it works. Any problems you might have should be directed to the LIST for rectification. The symbol &quot; _ &quot;<br>
indicates a continuing line of text. The reply box on this LIST does not permit the posting of one continuous line of<br>
text as seen in the original source code.<br>
<br>
<br>
Declare Function GetShortPathName Lib &quot;kernel32&quot; _<br>
Alias &quot;GetShortPathNameA&quot; (ByVal lpszLongPath As String, _<br>
ByVal lpszShortPath As String, ByVal cchBuffer As Long) _<br>
As Long<br>
<br>
Function LongToShort(LongFilename As String) As String<br>
Dim ShortFileName As String<br>
Dim Retval As Integer<br>
<br>
ShortFileName = Space$(256)<br>
<br>
Retval=GetShortPathName(LongFilename,ShortFileName,Len _<br>
ShortFileName))<br>
LongToShort = Left$(ShortFileName, Retval)<br>
End Function<br>
<br>
HTH,<br>
<br>
Jim aka Logit
 
Perfect! That is exectly what I was looking for.<br>
<br>
I tested it with a drive list, a dir list and a file list box.<br>
<br>
Private Sub File1_Click()<br>
If Right$(Dir1, 1) = &quot;\&quot; Then<br>
Label1 = LongToShort(Dir1 & File1)<br>
Else<br>
Label1 = LongToShort(Dir1 & &quot;\&quot; & File1)<br>
End If<br>
End Sub<br>
<br>
Thanks!<br>

 
Would it be ok if you posted the entire piece of your source code to the LIST so I could see what you accomplished ? I think I understand what you are saying, but I'm not certain I understand completely.<br>
<br>
Thanks<br>
<br>
Jim aka Logit
 
Certainly. In Module1 I pasted:<br>
<br>
Declare Function GetShortPathName Lib &quot;kernel32&quot; Alias &quot;GetShortPathNameA&quot; (ByVal lpszLongPath As String, ByVal lpszShortPath As String, ByVal cchBuffer As Long) As Long<br>
<br>
Function LongToShort(LongFilename As String) As String<br>
Dim ShortFileName As String<br>
Dim Retval As Integer<br>
ShortFileName = Space$(256)<br>
Retval = GetShortPathName(LongFilename, ShortFileName, Len(ShortFileName))<br>
LongToShort = Left$(ShortFileName, Retval)<br>
End Function<br>
<br>
...just like you posted. I created a label (Label1), a dir box, a drive box and a file list box (Dir1, Drive1 and File1), and used this code to test the LongToShort function:<br>
<br>
Private Sub Dir1_Change()<br>
File1 = Dir1<br>
End Sub<br>
<br>
Private Sub Drive1_Change()<br>
Dir1 = Drive1<br>
End Sub<br>
<br>
Private Sub File1_Click()<br>
If Right$(Dir1, 1) = &quot;\&quot; Then<br>
Label1 = LongToShort(Dir1 & File1)<br>
Else<br>
Label1 = LongToShort(Dir1 & &quot;\&quot; & File1)<br>
End If<br>
End Sub<br>
<br>
Label1 shows the MS-DOS path/filename. I just did this to test the function. When I use it in my project I'll have to find a way to get the full path to the filename returned by the Dir function. Do you have any ideas?<br>
<br>
Thanks again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top