How to get the latest file in a directory powershell

In this article let’s discuss about How to get the latest file in a directory powershell. Let’s go through the following methods without any delay.

Method 1:

$dir = "C:\test_code"
$latest = Get-ChildItem -Path $dir | Sort-Object LastAccessTime -Descending | Select-Object -First 1
$latest.name

Hope the above solution works.

Realted Posts : Pip command to install yaml 5.1.2