1

I use the following command in a batch file:

winscp sitename /command "get /filename.160313.tgz q:\localfolder\"

which downloads the file using winscp program.

What I'd like to do is have "160313" be automatically generated based on today's date.

How would I replace 160313 with such variable?

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
Uno Mein Ame
  • 1,060
  • 5
  • 16
  • 29

3 Answers3

1
@echo off
for /f "tokens=2 delims==" %%a in ('wmic OS Get localdatetime /value') do set "dt=%%a"
set "YY=%dt:~2,2%" & set "YYYY=%dt:~0,4%" & set "MM=%dt:~4,2%" & set "DD=%dt:~6,2%"
set "HH=%dt:~8,2%" & set "Min=%dt:~10,2%" & set "Sec=%dt:~12,2%"

echo %YY%%MM%%DD%

winscp sitename /command "get /filename.%YY%%MM%%DD%.tgz q:\localfolder\"
npocmaka
  • 55,367
  • 18
  • 148
  • 187
0
 C:\Users\User>echo %date:/= %
 Sun 13 03 2016

or for no spaces

set var=%date:/=%

Else you can use substring extraction

set var=%date:~-4%

for the year. See set /?.

  • I showed you how to get the year. Use generalisation to solve the rest of the problem. And your quickness of reply means you didn't read help. –  Mar 13 '16 at 10:39
0

WinSCP has its own syntax for generating timestamped names:

WinSCP.com /command ... "get /filename.%%TIMESTAMP#YYMMDD%%.tgz q:\localfolder\"

See also Formatting timestamp in batch file.

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992