Converting a Long Filename to Short.? 
Author Message
 Converting a Long Filename to Short.?

Could somebody give me an example on how to convert a filename longer to 8
bytes into a MSdos filename?  I've included the source I have below.

I need to be able to copy the SourceFile to a 8bit DestinationFile.  I need
to be able to leave the SourceFile unchanged in the long run.  Also, I need
to delete the 8bit character on exit of the program.

I'm new to this, so any help is appreciated.  Also, If it looks like the
code could be made easier to understand, please point it out to me.

Thanks for your time,

Jason Murdock

--------------------------------------------------

' All Variables MUST be declared
Option Explicit

Private Sub Cmdstart_Click()

    Dim gamelist As String
    Dim SourceFile As String
    Dim DestinationFile As String
    Dim ShellReturn As Long

        ' Selects a Game from the Filelist.
        gamelist = Filelist.filename

        SourceFile = gamelist                                             '
Define source file name.
        DestinationFile = "8bit word"                                  '
Define target file name.
        FileCopy SourceFile, DestinationFile                   ' Copy source
to target.  Has to be 8bits or less.
        SetAttr "DestinationFile", vbHidden                      ' Set
hidden attribute.

        ' Runs External Program with DestinationFile as a Variable.
        ShellReturn = Shell("gb97.exe " & DestinationFile, 1)

         ' I need to now delete the DestinationFile.  Not sure how to do
that yet though.
End Sub



Mon, 06 Nov 2000 03:00:00 GMT  
 Converting a Long Filename to Short.?

Quote:

>Could somebody give me an example on how to convert a filename longer to 8
>bytes into a MSdos filename?

Private Declare Function SKGetLongPathName Lib "VB5STKIT.DLL" _
                       Alias "GetLongPathName" _
                       (ByVal LongPath$, ByVal ShortPath$, _
                         ByVal BufferSize&) As Long

Private Declare Function OSGetShortPathName& Lib "kernel32" _
                       Alias "GetShortPathNameA" _
                       (ByVal lpszLongPath$, ByVal lpszShortPath$, _
                        ByVal cchBuffer&)

Public Function ShortFileName(ByVal LongFileName$) As String
'-----------------------------------------------------------------------
' Purpose:     Changes long filenames to it's equivalent short filename
'              (DOS 8.3 format)
' Arguments:   LongName (name of file)
' Returns:     Short filename
' Notes:       The file and directory must exist for this to work.
'              32-Bit function
'-----------------------------------------------------------------------
   Const BufferSize = 300
   Dim Buffer$
   Dim Result&

   On Error Resume Next
   LongFileName$ = Trim$(LongFileName$)
   If Len(LongFileName$) Then
      Buffer$ = String(BufferSize, Chr$(0))
      Result& = OSGetShortPathName&(LongFileName$, Buffer$, BufferSize)
      If Result& <> 0 Then
         ShortFileName = x_StripTerminator(Buffer$)
      End If
   End If
   On Error GoTo 0
End Function

Public Function LongFileName(ByVal ShortFileName$) As String
' Purpose:     Retrieve the long pathname version of a path possibly
'              containing short subdirectory and/or file names
' Arguments:   ShortFileName$ (name of file)
' Returns:     Long filename
' Notes:       The file and directory must exist for this to work.
'              32-Bit function
   Const BufferSize = 300
   Dim Buffer$
   Dim Result&

   On Error Resume Next
   ShortFileName$ = Trim$(ShortFileName$)
   If Len(ShortFileName$) Then
      Buffer$ = String(BufferSize, Chr$(0))
      Result& = SKGetLongPathName(ShortFileName$, Buffer$, BufferSize)
      If Result& <> 0 Then
         LongFileName = x_StripTerminator(Buffer$)
      End If
   End If
   On Error GoTo 0
End Function

Private Function x_StripTerminator(ByVal Expression As String) As String
' Returns a string without any zero terminator.  Typically,
' this was a string returned by a Windows API call.
'
' IN: [Expression] - String to remove terminator from
'
' Returns: The value of the string passed in minus any
'          terminating zero.

    Dim ZeroPos%

    ZeroPos% = InStr(Expression, Chr$(0))
    If ZeroPos% > 0 Then
        x_StripTerminator = Left$(Expression, ZeroPos% - 1)
    Else
        x_StripTerminator = Expression
    End If
End Function



Mon, 06 Nov 2000 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Converting a Long FIleName to it's short equivalent (Both possible shorts)

2. Convert long filenames to short filenames

3. Convert Long Filenames to Short Filenames in VB4 16-Bit

4. Converting long filenames to short filenames in VB4.0 16-bit

5. converting long filename paths to short

6. Converting long filenames to short

7. NEW: Converting long filenames to short

8. SHORT filename to LONG filename???

9. Short Filename to Long Filename ???

10. Long Filename -> Short Filename

11. SHORT filename to LONG filename???

12. Short filename to long filename

 

 
Powered by phpBB® Forum Software