Reputation: 17
I am running a task with Window task scheduler and WinSCP. Basically what I want to do is upload the newest file, everyday at 1pm (which is done in task scheduler), the problem is every day a new folder is created in F:\Satellite_Imagery\goes16\fd\NOMAP\todays
date (2020-05-12
, 2020-05-13
, etc.) How can I get the script to automatically find the newest folder and then the newest file in that folder?
This is the task code I have running (without a method for finding the newest folder)
/log="C:\Users\Myuser\Documents\WinSCP.log" /ini=nul /command "open ftp://Username:[email protected]" "put -latest F:\Satellite_Imagery\goes16\fd\NOMAP\2020-05-12\* /public_html/GOES16DATA/" "mv public_html/GOES16DATA/GOES*.jpg public_html/GOES16DATA/goestoday.jpg" "exit"
Upvotes: 1
Views: 634
Reputation: 202594
With WinSCP scripting, you can upload the latest file in a given folder (what you are doing now), or the latest folder. But not the latest file in the latest folder.
Though, if you know that the folder name is today, you can use %TIMESTAMP% syntax
to identify that folder (and then the -latest
switch to find the latest file in that folder):
"put -latest F:\Satellite_Imagery\goes16\fd\NOMAP\%%TIMESTAMP#yyyy-mm-dd%%\* /public_html/GOES16DATA/"
If you really need to find the latest folder, you will have to use a more powerful language. You can use WinSCP .NET assembly from e.g. PowerShell script.
You can start based on this article:
Uploading the most recent file. You will just have to repeat the selection code (Get-ChildItem
... Sort-Object
... Select-Object
) for both levels.
Upvotes: 1