×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Problem with spaces in File and Folder names

Problem with spaces in File and Folder names

Problem with spaces in File and Folder names

(OP)
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.

RE: Problem with spaces in File and Folder names

(OP)
After much trial and errors, this work

pinfo.Arguments = "e """ & zipFile & """ -O""" & unZipfldr & """ -p" & pwd

RE: Problem with spaces in File and Folder names

If you need to use " in your paths, this may be easier to read:

pinfo.Arguments = "e " & Chr$(34) & zipFile & Chr$(34) & " -O" & Chr$(34) & unZipfldr & Chr$(34) & " -p" & pwd

Chr$(34) is the equivalent of " (double-quotes)


---- Andy

There is a great need for a sarcasm font.

RE: Problem with spaces in File and Folder names

(OP)
Thank you so much. It made the code easier to read and maintain.

RE: Problem with spaces in File and Folder names

Of course you may go even further and do this:

CODE

Private Const sDQ As String = Chr$(34) 'Double Quotes "
...
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.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close