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 Andrzejek on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Runing Winrar from vbscript

Status
Not open for further replies.

paullem

Programmer
Jan 21, 2005
80
GB
Hi,

Does anyone know how to run winrar from a vbscript. I have a folder containing a number of large files which i want zipped into one '.rar' file. I've tried some examples I found but they don't seem to work.

Any help much appreciated,

Thanks
 
Hi [wink]
Try this Function
Code:
Function Zip(sFile,sArchiveName)
  'This function executes the command line
  'version of WinRAR and reports whether
  'the archive exists after WinZip exits.
  'If it exists then it returns true. If
  'not it returns an error message.

  Set oFSO = WScript.CreateObject("Scripting.FileSystemObject")
  Set oShell = WScript.CreateObject("Wscript.Shell")
 
  '--------Find Working Directory--------
  aScriptFilename = Split(Wscript.ScriptFullName, "\")
  sScriptFilename = aScriptFileName(Ubound(aScriptFilename))
  sWorkingDirectory = Replace(Wscript.ScriptFullName, sScriptFilename, "")
  '--------------------------------------
 
  '-------Ensure we can find Winrar.exe------
  If oFSO.FileExists(sWorkingDirectory & " " & "Winrar.EXE") Then
    sWinZipLocation = ""
  ElseIf oFSO.FileExists("C:\program files\Winrar\Winrar.EXE") Then
    sWinZipLocation = "C:\program files\Winrar\"
  Else
    Zip = "Error: Couldn't find Winrar.EXE"
    Exit Function
  End If
  '--------------------------------------
  oShell.Run """" & sWinZipLocation & "winrar.exe"" a -IBCK """ & _
  sArchiveName & """ """ & sFile & """", 0, True  
 
  If oFSO.FileExists(sArchiveName) Then
    Zip = 1
  Else
    Zip = "Error: Archive Creation Failed."
  End If
End Function


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top