0

I'd like to execute a script with options in a go-to-loop like so:

@echo off

rem my Array to loop thru

set Arr[0]=foo
set Arr[1]=bar
set Arr[2]=baz
set Arr[3]=bing
set Arr[4]=bang

After @Ken White's comment:

for /l %%x in (1, 1, 4) do (
    set VAR=%%Arr[%%x]%%
    "C:\Program Files (x86)\WinSCP\winscp.com" /ini=nul /script=C:\Dev\Automated_FTP_Scripts\%VAR%
    rem works as echo:
    call echo "C:\Program Files (x86)\WinSCP\winscp.com" /ini=nul /script=C:\Dev\Automated_FTP_Scripts\%VAR%
)

It still keeps returning the following error: Cannot open file "C:\Dev\Automated_FTP_Scripts\%Arr[0]%"

If I do a call echo ... it shows the correct path tho...

I tried different things:

  • set VAR=C:\Dev\Automated_FTP_Scripts\ + %%me%%
  • set VAR="C:\Dev\Automated_FTP_Scripts\ + %%me%%"
  • set VAR=C:\Dev\Automated_FTP_Scripts\%%me%%
  • set VAR="C:\Dev\Automated_FTP_Scripts\%%me%%"
  • "C:\Program Files (x86)\WinSCP\winscp.com" /ini=nul /script=%%Arr[%%x]%%

The question: How can I pass all_path to the winscp option /script?

One problem is that I don't know how to google that; I always get results on how to pass a parameter to a .bat file

toesslab
  • 5,092
  • 8
  • 43
  • 62
  • https://stackoverflow.com/q/2591758/62576 might help with this (including showing a much better way to iterate through a list). – Ken White Aug 21 '18 at 17:22
  • @KenWhite I'll give it a try... thank you – toesslab Aug 21 '18 at 17:24
  • @KenWhite Still the same issue – toesslab Aug 21 '18 at 19:36
  • Try [delayed expansion](https://ss64.com/nt/delayedexpansion.html). – Klitos Kyriacou Aug 21 '18 at 20:20
  • You also need `call` for the `winscp.com` execution, just like you do for `echo`; Anyway, I don't get why you need an interim variable `VAR`. By the way, the `for /L` loop should start at `0`, not at `1`... – aschipfl Aug 21 '18 at 20:55
  • `for /d %%x in (foo, bar, baz, bing, bang) do using delayedexpansion and `%%x` seems to work fine for me. – Ken White Aug 21 '18 at 20:56
  • So @KenWhite yes naturally the counter should start at 0... ;-) @Klitos Kyriacou `Delayed Expansion` wasn't necessary. The `call` to launch winscp was the only thing missing... thx to all. I'm a bit unsure wheter I should close that question "no longer reproducable" – toesslab Aug 22 '18 at 04:56
  • The interim variable `VAR`was just for testing – toesslab Aug 22 '18 at 07:28

0 Answers0