Solved

PKUNZIP through VB and passing LONG FILENAMES

Posted on 1998-09-30
4
250 Views
Last Modified: 2010-05-18
I am calling PKUNZIP with teh SHELL function and using VB to tell me all the ZIP files that exist in a directory and with that PKUNZIP those files into another directory.
THe problem arises when i use long filenames with PKUNZIP.  It has no clue about long filenames. It only recognizes the 8.3 filename style.  So ie. Shell("PKUNZIP.EXE LONG_FILENAME.ZIP") will not work at all, however, a call like Shell("PKUNZIP.EXE LONG_F~1.ZIP") will work. How do i find out what the equivalent 8.3 format is for a long filename. Some of you may say just pop a ~1 just before the .ZIP extension but what if in the directory there already exists a file with that same name (DOS assigns these unique ~#'s)? I could write a procedure that looks for all files with these long names and starts formulating these 8.3 formats for them, BUT the problem is DOS may have assigned a unique ~# that is different from mine.

Any suggestions?
0
Comment
Question by:ljaques
  • 4
4 Comments
 
LVL 3

Accepted Solution

by:
a111a111a111 earned 10 total points
ID: 1437542
I am sending you the code for short file name from long file name.
0
 
LVL 3

Expert Comment

by:a111a111a111
ID: 1437543
In module1.bas :
Option Explicit

Declare Function GetShortPathName Lib "kernel32" _
      Alias "GetShortPathNameA" (ByVal lpszLongPath As String, _
      ByVal lpszShortPath As String, ByVal cchBuffer As Long) As Long

   Public Function GetShortName(ByVal sLongFileName As String) As String
       Dim lRetVal As Long, sShortPathName As String, iLen As Integer
       'Set up buffer area for API function call return
       sShortPathName = Space(255)
       iLen = Len(sShortPathName)

       'Call the function
       lRetVal = GetShortPathName(sLongFileName, sShortPathName, iLen)
       'Strip away unwanted characters.
       GetShortName = Left(sShortPathName, lRetVal)
   End Function


in form1:

Private Sub Command1_Click()
Dim msg As String
     CommonDialog1.filename = "*.*"
     CommonDialog1.ShowOpen
     
     msg = "Long File Name: " & CommonDialog1.filename & vbCrLf
     msg = msg & "Short File Name: " & GetShortName(CommonDialog1.filename)
     msg = msg & vbCrLf & "________________________________________________________"
     msg = msg & vbCrLf & vbCrLf & "http://www.hili.com/~shay   E-Mail: shayplace@hotmail.com"
     
     MsgBox msg
End Sub

Private Sub Command2_Click()
Unload Me
End Sub

Private Sub Form_Load()

End Sub


You can download the complete project form my site as
http://www.hili.com/~shay/filename.zip


0
 
LVL 3

Expert Comment

by:a111a111a111
ID: 1437544
In module1.bas :
Option Explicit

Declare Function GetShortPathName Lib "kernel32" _
      Alias "GetShortPathNameA" (ByVal lpszLongPath As String, _
      ByVal lpszShortPath As String, ByVal cchBuffer As Long) As Long

   Public Function GetShortName(ByVal sLongFileName As String) As String
       Dim lRetVal As Long, sShortPathName As String, iLen As Integer
       'Set up buffer area for API function call return
       sShortPathName = Space(255)
       iLen = Len(sShortPathName)

       'Call the function
       lRetVal = GetShortPathName(sLongFileName, sShortPathName, iLen)
       'Strip away unwanted characters.
       GetShortName = Left(sShortPathName, lRetVal)
   End Function


in form1:

Private Sub Command1_Click()
Dim msg As String
     CommonDialog1.filename = "*.*"
     CommonDialog1.ShowOpen
     
     msg = "Long File Name: " & CommonDialog1.filename & vbCrLf
     msg = msg & "Short File Name: " & GetShortName(CommonDialog1.filename)
     msg = msg & vbCrLf & "________________________________________________________"
     msg = msg & vbCrLf & vbCrLf & "http://www.hili.com/~shay   E-Mail: shayplace@hotmail.com"
     
     MsgBox msg
End Sub

Private Sub Command2_Click()
Unload Me
End Sub

Private Sub Form_Load()

End Sub


You can download the complete project form my site as
http://www.hili.com/~shay/filename.zip


0
 
LVL 3

Expert Comment

by:a111a111a111
ID: 1437545
Sorry for the duplicate here the server has a problem.

Go and download the project from the site:
http://www.hili.com/~shay/filename.zip 

0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question