-1

I want to search the latest folder and than copy latest file from that folder. I know how to search for latest file in a folder but stuck with how to find latest folder in a folder.

I am trying to transfer file to a FTP location using WinSCP script. Below is my script:

option batch abort
option confirm off
open sftp://XYZ:ABC@123/ -hostkey="ssh-rsa w w w w w w w w w w"
put -latest C:\A\B\2017\*  "/ "
exit
Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328

1 Answers1

0

To find the latest file in the lastest folder in PowerShell, you could do the following:

$FirstFolder = `
    Get-ChildItem -Force `
    | Where-Object -Property PSIsContainer -EQ -Value $true `
    | Sort-Object -Property LastWriteTime -Descending `
    | Select-Object -First 1

$FirstItemPath = `
    Get-ChildItem -Path $FirstFolder -Force `
    | Where-Object -Property PSIsContainer -EQ -Value $false `
    | Sort-Object -Property LastWriteTime -Descending `
    | Select-Object -First 1 -ExpandProperty FullName
Shawn Esterman
  • 2,292
  • 1
  • 10
  • 15
  • And then upload the selected file using [WinSCP .NET assembly from the PowerShell script](https://winscp.net/eng/docs/library_powershell). – Martin Prikryl Aug 22 '17 at 15:42