VBScripting folder names with space issue's

I have created a VBScript to zip a folder to a file in another folder.  So far this has worked as like charm until I cam accross folders with spaces etc...

I have searched high and low....and can not seem to solve this issue.  I must be overlooking something, and this should be simple!  As the case may be I am in urgent need to complete this script so I have put a 500 point value on it.

Below is the script I have created, you will need the Winzip to complete this task.

NOTE:  WE CAN NOT USE THE WINZIP ADDON TO DO COMMAND LINE.............

Dim Wshell,fso,fld,fil,FileList
Set fso = CreateObject("Scripting.FileSystemObject")
Set Wshell = CreateObject("Wscript.Shell")

'delete if exists folder
If fso.FolderExists("c:\test")Then
      fso.DeleteFolder("c:\test")
End If

'create folder
Set fld =fso. CreateFolder("c:\test")

'folder and files to capture
Set fld0 = fso.GetFolder("C:\Program Files\Windows NT")  ' this seems to get truncated and will not zip up

' zip the files
Wshell.Run "winzip -min  -a -r C:\test\winnt.zip " &  fld0

'cleanup
Set Wshell = Nothing
Set fld = Nothing
Set fld0 = Nothing
Set fso = Nothing

jvpohlAsked:
Who is Participating?
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Try enclosing the path in quotes:   (you don't need fso.GetFolder either)

    'folder and files to capture
    fld0 = "C:\Program Files\Windows NT"

    ' zip the files
     Wshell.Run "winzip -min  -a -r -p -es -hs  C:\test\winnt.zip " & Chr(34) & fld0 & Chr(34)

Remove this line:

    Set fld0 = Nothing

0
 
jvpohlAuthor Commented:
here are the result from winzip:

Action: Add (and replace) files Include subfolders: yes Save full path: no
Warning: name not matched: C:\Program
Warning: name not matched: Files\Windows
Warning: name not matched: NT
Error: No files were found for this action that match your criteria - nothing to do. (C:\test\winnt.zip)
0
 
jvpohlAuthor Commented:
Ok...not really sure how to cancel this.....but I have the answer!  

DOS IS KILLING ME!!!!!  

Dim Wshell,fso,fld,fil,FileList
Set fso = CreateObject("Scripting.FileSystemObject")
Set Wshell = CreateObject("Wscript.Shell")

'delete if exists folder
If fso.FolderExists("c:\test")Then
      fso.DeleteFolder("c:\test")
End If

'create folder
Set fld =fso. CreateFolder("c:\test")

'folder and files to capture
Set fld0 = fso.GetFolder("C:\progra~1\window~1")  ' this works perfectly!

' zip the files
Wshell.Run "winzip -min  -a -r -p -es -hs  C:\test\winnt.zip " & fld0

'cleanup
Set Wshell = Nothing
Set fld = Nothing
Set fld0 = Nothing
Set fso = Nothing
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.