1

I need to transfer the latest file in a folder to aws server using a simple batch script. I am getting a date-stamped filename so ideally the largest file name should be the latest

The code used is as follows

@echo off
SET longfile =''

for %%a  in (c:\Users\Admin\Desktop\batch\*) do (


if %%a GTR %longfile%

%longfile% = %%a

)

pscp -i  c:\putty\pass.ppk %longfile% ubuntu@ec2-XXX-us-west-2.compute.amazonaws.com:/home/ubuntu/

The above script does not work as the pscp command returns the error file not found.

Joe
  • 11
  • 3
  • Largest file is the latest? how about created file? a new file will be the latest. – Gerhard Feb 08 '18 at 10:04
  • So the main problem here is that `pscp` is not found? Sounds like you need to add it's directory to your PATH environment variable, or use the full path to the exe e.g. `C:\putty\pscp.exe -i ...` – Jonathon McMurray Feb 08 '18 at 10:42

1 Answers1

0

It could be as simple as:

FOR /F "delims=" %%i IN 'dir "c:\Users\Admin\Desktop\batch" /b /a-d-h /t:c /od') do set "latest=%%i"
echo Latest file is: %latest%
Gerhard
  • 22,678
  • 7
  • 27
  • 43