How to take a path including special char like (C:\WIN & SCP\Audit\)

Advertisement

hlakki_India
Guest

How to take a path including special char like (C:\WIN & SCP\Audit\)

Hi Team,
Greetings!!

I have two bat files one is to create parm parameters for Winscp and another one is for WinSCP execution.

Here the problem is first bat file is working smoothly and giving 4 parms to Winscp (i.e: USER, "remote path", "local path", "local variable").

Here my script is with example sites :

this below line is the end of example1.bat having it will trigger example2.bat with following /parms

./example2.bat %USER% %RemoteFolder% %localvariable%  "%Localpath%"

example2.bat is having below script

@echo off
 
"C:\Users\WinSCP.com" ^
  /log="C:\WinsCP.log" /ini=nul ^
  /command ^
"open ftp://%1%@example.com/" ^
"lcd %4%" ^   
"cd /home/%1/drive/%2" ^
"cd output" ^
"get file1.txt %3%%TIMESTAMP#yymm%%file1.txt"   ^
   "exit"
 
set WINSCP_RESULT=%ERRORLEVEL%
if %WINSCP_RESULT% equ 0 (
  echo Success
) else (
  echo Error
)
 
exit /b %WINSCP_RESULT%

Here the problem is @lcd the path is not taking whenever it's having special char in the path like (C:\WIN & SCP\Audit\)

I tried to give with double quotes & single double quotes.

please help me with this.

Thanks
hemanth kumar

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
40,587
Location:
Prague, Czechia

Re: How to take a path including special char like (C:\WIN & SCP\Audit\)

This is rather a batch file question, than a WinSCP question.

The only WinSCP-specific part of this is doubling of double-quotes, but you you seem to be aware of that:
https://winscp.net/eng/docs/commandline#syntax

Regarding the batch-file-part: If you pass "%Localpath%" as a 4th parameter of a batch file, the %4 will contain those quotes. So you have to cater for that in your other batch file.

You want this:
  "lcd ""C:\WIN & SCP\Audit\""" ^

And as %4 contains one pair of double-quotes already, you need to use:
  "lcd "%4"" ^

Also the batch file syntax for parameters is %N, while you inconsistently sometimes have incorrectly %N% and sometimes correctly %N.

Last, you seem to have the indentation wrong:
https://winscp.net/eng/docs/faq_batch_file#newline_escaping

Reply with quote

Advertisement

You can post new topics in this forum