macbug
macbug

Reputation: 121

Find the latest created JSON using Powershell

Lets say i have a folder which contains of several different file types. One among them are JSON files. It is not always so that the latest created file in the folder is a JSON file.

My problem is that i need to find the latest JSON file, not the latest file.

Thanks in advance.

Upvotes: 0

Views: 108

Answers (1)

supermerio
supermerio

Reputation: 240

User Get-ChildItem (gci) and filter on *.json

You can then sort by LastWriteTime in descending order and retrieve the first item in the array of files.

$jsonFiles = gci c:\jsonFiles -Filter *.json

($jsonFiles | Sort LastWriteTime -Descending)[0]

Upvotes: 1

Related Questions