Solved

PKUNZIP through VB and passing LONG FILENAMES

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

932 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

11 Experts available now in Live!

Get 1:1 Help Now