Batch File not reading Varibles

Advertisement

Apurv
Joined:
Posts:
1
Location:
Apurv

Batch File not reading Varibles

Hello,

I have created a batch script{below} that refers to Credentials file:
set Pathname="C:\Program Files\WinSCP"
pushd %Pathname%
winscp.com /script="D:\Test\Credentials.txt"


The files I am trying to extract come with date and a random stamp. All the files, including previous days files, are placed in same directory.
eg:
User_20131227_010203.txt
User_20131226_098778.txt
User_20131225_093110.txt

I have to extract latest files.I am trying to use 'User__%date:~-4,4%%date:~-7,2%%date:~-10,2%-*'
But SFTP commands don't seem to understand these variables.

Any way to extract latest files or read variables?
Any help is appreciated.

Thanks!
[/img]

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
41,468
Location:
Prague, Czechia

Re: Batch File not reading Varibles

WinSCP supports only basic syntax %NAME%, not the advanced syntax you are using.
Specifically, it is using ExpandEnvironmentStrings WinAPI function:
https://learn.microsoft.com/en-us/windows/win32/api/processenv/nf-processenv-expandenvironmentstringsw

You can store the result of %date:~-4,4%%date:~-7,2%%date:~-10,2% to a temporary variable in your batch file and use that from the script.

Reply with quote

Advertisement

You can post new topics in this forum