Answer the question
In order to leave comments, you need to log in
Answer the question
In order to leave comments, you need to log in
$path = "c:\test\"
$files_to_delete = @()
$list_of_folders = Get-ChildItem -Path $path -Recurse -directory
foreach ($folder in $list_of_folders)
{
$oldest_file = get-childitem -path $folder. fullname -File | sort lastwritetime -descending | select -last 1
$files_to_delete += $oldest_file
}
$files_to_delete
check if it finds the files correctly and let you know. if correct - I will give the second part where he will delete them.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question