Monday, November 3, 2014

Latest file in a directory with subfolders

Very often we need to find the latest/most recent files in a folder. You can use the below script to copy the files into a directory. This will only copy the latest file to the directory.

get-childitem $sourceDir | where {(!$_.PSIsContainer) -and ($_.FullName -like '*.filetype*') } | sort-object lastwritetime | foreach {Copy-Item -Path $_.FullName $_.DestDir  -Force }

No comments:

Post a Comment