Variable current date folder name for Windows command?

Hello,

What is the problem you are having with rclone?

I was using rclone with a cheap VPS with debian and I used this command which worked fine :

rclone --checksum -vv copy GoogleDrive:Kv/`date +%Y/%Y-%m`av GoogleSuite:1/Kv/`date +%Y/%Y-%m`av

Now I am trying to adapt the same command in Windows with Rclone CLI and I am stuck (e.g. : I have exchanged / with \)!

rclone --checksum -vv copy GoogleDrive:Kv\`date +%Y\%Y-%m`av GoogleSuite:1\Kv\`date +%Y\%Y-%m`av

What is your rclone version (output from rclone version)

rclone v 1.56.0

Which OS you are using and how many bits (eg Windows 7, 64 bit)

Windows 8.1 64bit home

Which cloud storage system are you using? (eg Google Drive)

From Google Drive to Google Gsuite

A log from the command with the -vv flag

Command copy needs 2 arguments maximum: you provided 4 non flag arguments: ["GoogleDrive:Kv\\`date" "+%Y\\%Y-%m`av" "GoogleSuite:1\\Kv\\`date" "+%Y\\%Y-%m`av"]

Many thanks in advance :wink:

If you can use PowerShell, that would be your best bet. Then you can use Get-Date (or [datetime]::Now, or New-Object DateTime, ...) to get a .NET DateTime object, which you can easily format.

Something like this:

rclone --checksum -vv copy GoogleDrive:Kv/$((Get-Date).ToString("yyyy\/yyyy-MM"))av GoogleSuite:1/Kv/$((Get-Date).ToString("yyyy\/yyyy-MM"))av
1 Like

using dos style batch file,

for /f "tokens=2 delims==" %%I in ('wmic os get localdatetime /format:list') do set datetime=%%I
set thedate=%datetime:~0,4%%datetime:~4,2%%datetime:~6,2%
rclone  lsd wasabi01:testfolder01/%thedate%

woud output

rclone ls wasabi01:testfolder01/20210828 
      275 file.txt

Wow ! Many thanks albertony. You don't know how much it helped me! I much appreciated! :wink:
I went for your solution with Powershell, and it finally worked like a charm. :wink:

As I have spent quite a few hours trying to understand this, here is what I have done in case it can help someone else (with explanations on how to automate the script with Windows Task scheduler) :

(Assuming you have already Powershell installed on your computer)
I have created a txt file. I renamed it test.ps1
Then right-click on the "test.ps1" file and select open

Then paste the code :
In fact, do not use this one! :

.\rclone --checksum -vv copy GoogleDrive:Kv/$((Get-Date).ToString("yyyy\/yyyy-MM"))av GoogleSuite:1/Kv/$((Get-Date).ToString("yyyy\/yyyy-MM"))av

Use this one :wink: : (add the path where your rclone.exe is located, otherwise it won't load latter on with Windows Task scheduler! And I have also added the log info into a local log file. Like that, I can be sure that it has run)

C:\prog\rclone\rclone.exe --checksum -vv copy GoogleDrive:Kv/$((Get-Date).ToString("yyyy\/yyyy-MM"))av GoogleSuite:1/Kv/$((Get-Date).ToString("yyyy\/yyyy-MM"))av --log-file="C:\prog\rclone\mylogfile.txt"

Save the file and run it (F5).

Then add a Windows Task schedule to it (see image 2021-08-28-162159.png ):
Program :
powershell
Add arguments :
-NoLogo -NoProfile -NonInteractive -File "C:\prog\rclone\Kv.ps1"
(please notice the quotes after File as I had this problem)

Helping sources : How can I write batch sync command with a timestamp log file in Windows 10? - #2 by albertony
How to Automate PowerShell Scripts with Task Scheduler
I have also added log to the rclone command see here : How to generate log file for rclone? - #2 by thestigma

Again many thanks to albertony :wink: and also jojothehumanmonkey :wink:

1 Like

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.