P
P
Pavel Kaptur2016-02-17 20:43:15
Windows
Pavel Kaptur, 2016-02-17 20:43:15

How to quickly find the newest file in a folder?

there was a task to delete the old files from the folder, the modification date of which is more than the modification date of the newest file in this folder by X days. There can be many, many hundreds of thousands of files there. The question is how to find the newest file using api in the minimum time / resources.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
M
Maxim Timofeev, 2016-02-17
@webinar

Use the search by folder in the search criteria, set the modification date

E
Eugene, 2016-02-17
@yellowmew

I don’t know about api, your task is easily solved by a script.
for example powershell:

$files=Get-ChildItem * -File | sort -Descending CreationTime
$date=$files[0].CreationTime.AddDays(-50)
$files | where {$_.CreationTime -le $date} | Foreach {Write-host $_.FullName}

Instead of displaying it on the screen, you can do whatever you want with these files, for example, delete them.

V
Vladimir Martyanov, 2016-02-17
@vilgeforce

FindFirstFile + FindNextFile + FindClose. For each found file - GetFileTime

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question