473,386 Members | 1,715 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Using a Process to Extract a file from Winzip archive

Hi,

I am trying to extract zipped files using Winzip in my VB.net application and I ran into 2 stone walls.

1. How do you handle file names with spaces. See psiProcess.Arguments
For example "My Data file Apr2007.zip"? In the example below, the
parameter pZippedFile contains the file name with spaces and the
pExtractFolder contains the folder where it should be extracted.
2. Is there anyway to get the extracted file name so that I can rename it? For
example: The zipped file is "NYC Data.zip", the extracted file is Data.txt and
It would like to rename it as NYC_Data.txt

Platform: Windows 2000
Language: VB.net
Source Code: See below
Input Used: Any zip file named as I specified in bullet point #1
Error Codes: None but the application hangs and does not extract files
however if I rename all the zip files to have no spaces it works
In addition the minimized zip file shows the zip file name as
my.zip ... everything after the first spaces is truncated.
Please note I tried quotes and brackets. I also tried to find
answers googling (sp?) and came up empty.

Any help on this would greatly be appreciated. I have been pulling out my hair
on this problem for quite awhile.

Thanks again,
LearningVB.net

Expand|Select|Wrap|Line Numbers
  1. Public Function ZipExtract(ByVal pZippedFile As String, _
  2.                                ByVal pExtractFolder As String) As Boolean
  3.  
  4.         '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  5.         '~~~ This function extracts files from a zipped archive
  6.         '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  7.  
  8.         Dim psiProcess As New ProcessStartInfo
  9.         Dim udtProc As New Process
  10.  
  11.         Try
  12.             '~~~Set the startup information for the process.
  13.             psiProcess.FileName = "C:\Program Files\WinZip\Winzip32.exe"
  14.             psiProcess.WorkingDirectory = pExtractFolder
  15.             psiProcess.WindowStyle = ProcessWindowStyle.Hidden
  16.             psiProcess.ErrorDialog = False
  17.             psiProcess.CreateNoWindow = True
  18.             psiProcess.Arguments = "-min -e " & pExtractFolder & "\ '" & pZippedFile & "'  " & pExtractFolder & "\"
  19.             udtProc = Process.Start(psiProcess)
  20.             udtProc.WaitForExit()
  21.             udtProc.Close()
  22.             ZipExtract = True
  23.  
  24.         Catch ex As DuplicateNameException
  25.             '~~~ change name on the fly?
  26.         Catch ex As Exception
  27.             If ApplicationUtility.LoadArray(ex.Message) = True Then
  28.                 ZipExtract = False
  29.             End If
  30.         End Try
  31.  
  32.     End Function
  33.  
Dec 6 '07 #1
3 3893
Hi,

I am trying to extract zipped files using Winzip in my VB.net application and I ran into 2 stone walls.

1. How do you handle file names with spaces. See psiProcess.Arguments
For example "My Data file Apr2007.zip"? In the example below, the
parameter pZippedFile contains the file name with spaces and the
pExtractFolder contains the folder where it should be extracted.
2. Is there anyway to get the extracted file name so that I can rename it? For
example: The zipped file is "NYC Data.zip", the extracted file is Data.txt and
It would like to rename it as NYC_Data.txt

Platform: Windows 2000
Language: VB.net
Source Code: See below
Input Used: Any zip file named as I specified in bullet point #1
Error Codes: None but the application hangs and does not extract files
however if I rename all the zip files to have no spaces it works
In addition the minimized zip file shows the zip file name as
my.zip ... everything after the first spaces is truncated.
Please note I tried quotes and brackets. I also tried to find
answers googling (sp?) and came up empty.

Any help on this would greatly be appreciated. I have been pulling out my hair
on this problem for quite awhile.

Thanks again,
LearningVB.net

Expand|Select|Wrap|Line Numbers
  1. Public Function ZipExtract(ByVal pZippedFile As String, _
  2.                                ByVal pExtractFolder As String) As Boolean
  3.  
  4.         '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  5.         '~~~ This function extracts files from a zipped archive
  6.         '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  7.  
  8.         Dim psiProcess As New ProcessStartInfo
  9.         Dim udtProc As New Process
  10.  
  11.         Try
  12.             '~~~Set the startup information for the process.
  13.             psiProcess.FileName = "C:\Program Files\WinZip\Winzip32.exe"
  14.             psiProcess.WorkingDirectory = pExtractFolder
  15.             psiProcess.WindowStyle = ProcessWindowStyle.Hidden
  16.             psiProcess.ErrorDialog = False
  17.             psiProcess.CreateNoWindow = True
  18.             psiProcess.Arguments = "-min -e " & pExtractFolder & "\ '" & pZippedFile & "'  " & pExtractFolder & "\"
  19.             udtProc = Process.Start(psiProcess)
  20.             udtProc.WaitForExit()
  21.             udtProc.Close()
  22.             ZipExtract = True
  23.  
  24.         Catch ex As DuplicateNameException
  25.             '~~~ change name on the fly?
  26.         Catch ex As Exception
  27.             If ApplicationUtility.LoadArray(ex.Message) = True Then
  28.                 ZipExtract = False
  29.             End If
  30.         End Try
  31.  
  32.     End Function
  33.  

Hi I have a suggestion for you. I'm still somewhat new to VB but it should work in theory. I know that VB can find the files even when they heve spaces so..... why not use FileCopy command and create a temporary copy of the file with a name like "UnzipTemp". Then use your function to unzip this temp file and delete the temporary.
(Not sure if this is last bit can be done)
Save the old filename when you copy it as a string, then change the string slightly to make it a new filename.
(edit) I looked it up it can be done with only very little code

Hope this helps

James
Dec 6 '07 #2
Hi I have a suggestion for you. I'm still somewhat new to VB but it should work in theory. I know that VB can find the files even when they heve spaces so..... why not use FileCopy command and create a temporary copy of the file with a name like "UnzipTemp". Then use your function to unzip this temp file and delete the temporary.
(Not sure if this is last bit can be done)
Save the old filename when you copy it as a string, then change the string slightly to make it a new filename.
(edit) I looked it up it can be done with only very little code

Hope this helps

James
James ...
Thank you for the suggestion. I will try it out and let you know what the outcome is.

Thanks again
Learningvbnet
Dec 7 '07 #3
Plater
7,872 Expert 4TB
Winzip should have some command line parameters to chose a destination directory (and maybe a filename)
But since you're just using the program and not API calls, they might not have included a rename feature in it.


Why not just use the built in ZIP/UNZIP objects?
Dec 7 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

11
by: Grasshopper | last post by:
Hi, I am automating Access reports to PDF using PDF Writer 6.0. I've created a DTS package to run the reports and schedule a job to run this DTS package. If I PC Anywhere into the server on...
2
by: Terry Olsen | last post by:
Using the following code, I get the error "No process is associated with this object" when calling the WinZip.WaitForExit() method. After I click the "Break" or "Continue" button on the dialog,...
15
by: Karl | last post by:
Hi all, I regularly use FTP to place Self Extracting Zip files on the web for remote users to update their datafiles. Works very nicely. I have automated the creation of the initial zip file (...
5
by: Michael Sperlle | last post by:
Is it possible? Bestcrypt can supposedly be set up on linux, but it seems to need changes to the kernel before it can be installed, and I have no intention of going through whatever hell that would...
10
by: Elric02 | last post by:
I'm currently trying to get access to the Python source code, however whenever I try to extract the files using the latest version of WinZip (version 10) I get the following error "error reading...
0
by: Craig Buchanan | last post by:
when i try to open a file that has been compressed with GZipStream (source from microsoft's 101 Samples for Visual Studio 2005), i get an "invalid archive" message from winzip, zipgenius and xp's...
1
by: Josec84 | last post by:
Im writing a script and need help. I need to extract a file using the command prompt. Are there commands to extract files or unzip files(without downloading any add-ons)??? Let's say i have a file...
5
by: Nilam2477 | last post by:
i need to zip the files/folder. How can i use winzip32.exe in C# code to programatically zip the files or folder. If you could provide some sample code that would be great. Thanks
0
by: yugho | last post by:
I'm sorry if I post Winzip question here, but I met a problem. I was running Winzip command by using process in VB.Net, but I had error that I don't know how to trace. 1. I create a batch file:...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.