How to create directory and move to this new directory

Advertisement

a74399
Joined:
Posts:
1

How to create directory and move to this new directory

I want to schedule some commands on a daily frequency and create different directories every day (with the filename being the date and time), and upload some files afterward.
So I basically need something like:
mkdir %TIMESTAMP#yyyy-mm-dd-hh%
cd "last argument"
Is there a way to do this?
Thanks in advance.

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
38,177
Location:
Prague, Czechia

Re: How to create directory and move to this new directory

The simplest solution is just repeat %TIMESTAMP#yyyy-mm-dd-hh%. I understand that there's a small risk that "hour" changes between the two lines.

If you want to be 100% sure, you can query the timestamp before starting the actual script (based on Formatting Timestamp in Batch File):
for /F "tokens=* USEBACKQ" %%F in (
    `winscp.com /command "echo %%TIMESTAMP#yyyy-mm-dd-hh%%" "exit"`
) do set THE_TIMESTAMP=%%F
 
winscp.com /script=script.txt
And then in the script.txt WinSCP script, you can use %THE_TIMESTAMP% environment variable repeatedly.
Alternatively, instead of environment variable, you can use script argument.

Reply with quote

Advertisement

You can post new topics in this forum