Tominator
Tominator

Reputation: 1224

Windows equivalent of find -cmin +24

What would be the windows (command prompt) equivalent of the following command?

find -cmin +24 | xargs rm

This command finds all files with "status changed over 24 minutes ago", and then removes them.

It is suggested in the php.ini config file as a way to clear old session files, but my server is a windows system.

I've found out that 'dir' has the /T:A option, but that only gets me so far.. How would I delete the files older than 24 minutes?

Cheers!

Upvotes: 2

Views: 354

Answers (1)

Russell Smith
Russell Smith

Reputation: 26

While this isn't in command, if you've got Powershell on the machine, the following script will work.

$oldest = [system.datetime]::Now.AddMinutes(-1)
# Directory to clean up
$directory = "C:\Temp\test2"

# This lists the files it would delete
dir $directory | where-object {$_.LastWriteTime -lt $oldest}

# Uncomment this line to delete them
#dir $directory | where-object {$_.LastWriteTime -lt $oldest} | erase

Upvotes: 1

Related Questions