Powershell Script to get a latest file with a Specific dynamic name

Advertisement

nashreddy369@gmail.com
Joined:
Posts:
1

Powershell Script to get a latest file with a Specific dynamic name

Hi,
i am new to this topic i saw how to download the most recent file powershell script but i have an additional requirement.
in addition to most recent criteria, i want to download a specific file name (eg: file_1234_shape.txt) with dynamic part which keeps on changing, the *1234* part in the example changes everyday but the rest remains same.
please provide a powershell script to download latest file with Specific Dynamic name.
i am currently using the powershellscript to download most recent file.

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
41,378
Location:
Prague, Czechia

Re: Powershell Script to get a latest file with a Specific dynamic name

So just add your constraint. Something like:
$latest =
    $directoryInfo.Files |
    Where-Object { -Not $_.IsDirectory } |
    Where-Object { $_.Name.Contains("1234") } |
    Sort-Object LastWriteTime -Descending |
    Select-Object -First 1
(assuming you are using this script: https://winscp.net/eng/docs/script_download_most_recent_file#powershell)

Reply with quote

Advertisement

You can post new topics in this forum