2

This thread outlines how to code batch hybrids that may include a combination of several scripting languages, such as batch, VBS, JScript, PowerShell, etc. The question is, whether a batch hybrid treats "foreign" language blocks as "functions", meaning calls to these blocks may include arguments like regular and delayed expansion batch variables, that are referenced as usual arguments like %1, %2, etc?

Example below shows the approach in the task of unzipping a file, while using this file unzip code, but it gives an error in Win10 64-bit - why? Note, the linked file unzip code gives an error as well when run in Win 10, but a different one.

<!-- : Begin batch script
@echo off
set "dir=C:\Temp\" & set "file=%USERPROFILE%\Downloads\archive.zip\"
cscript //nologo "%~f0?.wsf" "%dir%" "%file%"
exit /b

----- Begin wsf script --->
<job><script language="VBScript">
 set fso = CreateObject("Scripting.FileSystemObject")
 If NOT fso.FolderExists(%1) Then
 fso.CreateFolder(%1)
 End If
 set objShell = CreateObject("Shell.Application")
 set FilesInZip = objShell.NameSpace(%2).items
 objShell.NameSpace(%1).CopyHere(FilesInZip)
 set fso = Nothing
 set objShell = Nothing
</script></job>

:: Error
..\test.bat?.wsf(9, 8) Microsoft VBScript compilation error: Invalid character
Community
  • 1
  • 1
sambul35
  • 1,000
  • 11
  • 21

1 Answers1

1

In vbscript the first argument is : wscript.Arguments(0)

the second argument is : wscript.Arguments(1)

So,you should write it like that : `

----- Begin wsf script --->
<job><script language="VBScript">
 set fso = CreateObject("Scripting.FileSystemObject")
 If NOT fso.FolderExists(wscript.Arguments(0)) Then
 fso.CreateFolder(wscript.Arguments(0))
 End If
 set objShell = CreateObject("Shell.Application")
 set FilesInZip = objShell.NameSpace(wscript.Arguments(1)).items
 objShell.NameSpace(wscript.Arguments(0)).CopyHere(FilesInZip)
 set fso = Nothing
 set objShell = Nothing
</script></job>
Hackoo
  • 15,943
  • 3
  • 28
  • 59
  • 1
    Works perfect. I wonder, how a similar purpose batch & JScript hybrid would look like? :) – sambul35 Jul 27 '16 at 05:41
  • @sambul35 Don't forget to upvote and accept it as an answer in this case ;) – Hackoo Jul 27 '16 at 06:18
  • See also this [question](http://stackoverflow.com/questions/38612727/unzip-a-file-with-batch-jscript-hybrid-using-common-variables) :) – sambul35 Jul 27 '16 at 12:22