Solved

PKUNZIP through VB and passing LONG FILENAMES

Posted on 1998-09-30
4
246 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

708 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now