Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with spaces in File and Folder names 1

Status
Not open for further replies.

malaygal

IS-IT--Management
Feb 22, 2006
192
US
I was hoping somebody can help mw with this, as I have been working on this for the past couple of days now.
I am trying to automate unzipping of files as follows:

Dim pinfo As New ProcessStartInfo
pinfo.FileName = "C:\Program Files\7-Zip\7z.exe"
Dim zipFile As String = "C:\File to Zip.7z"
Dim unZipfldr As String = "C:\UnZip Folder"
Dim pwd As String = "test"

pinfo.Arguments = "e " & zipFile & " -O" & unZipfldr & " -p" & pwd
Dim p As Process = Process.Start(pinfo)


This does not work with spaces in the file and folder names and I do not have control in naming them.
I tried enclosing the name in single-quote, double-quote and escape the names with \, but to no avail.
Any help and/or guidance will be greatly appreciated.
 
After much trial and errors, this work

pinfo.Arguments = "e """ & zipFile & """ -O""" & unZipfldr & """ -p" & pwd
 
If you need to use [tt]"[/tt] in your paths, this may be easier to read:
[tt]
pinfo.Arguments = "e " & Chr$(34) & zipFile & Chr$(34) & " -O" & Chr$(34) & unZipfldr & Chr$(34) & " -p" & pwd
[/tt]
Chr$(34) is the equivalent of [tt]"[/tt] (double-quotes)


---- Andy

There is a great need for a sarcasm font.
 
Thank you so much. It made the code easier to read and maintain.
 
Of course you may go even further and do this:

Code:
Private Const sDQ As String = Chr$(34) [green]'Double Quotes "[/green]
...
pinfo.Arguments = "e " & sDQ & zipFile & sDQ & " -O" & sDQ & unZipfldr & sDQ & " -p" & pwd

Or declare it as Public in a Module so you can use it anywhere in your App if you need to.
[pc2]


---- Andy

There is a great need for a sarcasm font.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top