D
D
dobromin2017-01-17 16:13:50
Windows
dobromin, 2017-01-17 16:13:50

Is there a ready script?

Hello!
We need a script that would delete the oldest file recursively in folders and subfolders.
Please tell me where you can find it, I myself don’t understand scripts at all.
Thank you!
Windows
js ps bat

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
azarij, 2017-02-06
@dobromin

$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 question

Ask a Question

731 491 924 answers to any question