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?

3
  • take a look at this : stackoverflow.com/a/19799236/388389 Commented Mar 13, 2016 at 10:52
  • You'd need to show us the format in which your machine displays the variable %date%. Commented Mar 13, 2016 at 10:52
  • see here Commented Mar 13, 2016 at 10:53

3 Answers 3

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\"
Sign up to request clarification or add additional context in comments.

Comments

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 /?.

1 Comment

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.
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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.