V
V
vkrutik2019-05-22 19:54:37
Network administration
vkrutik, 2019-05-22 19:54:37

How to delete files by date?

There are about 80,000 files in one folder on the hosting.
Through FTP, the client shows only 10 thousand at a time. Explorer in CPANEL does not load such a folder.
There is no SSH access to the hosting.
The task is to remove the old ones from these files (before a certain date).
How to do it quickly and easily?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
vkrutik, 2019-05-22
@vkrutik

UPD. I asked myself and found the solution myself.
Found a PHP script that deletes files in a directory older than the specified number of days. Works smart. mb help someone

<?
$days = 100;
$dir = dirname ( __FILE__ );
 
$nofiles = 0;
 
    if ($handle = opendir($dir)) {
    while (( $file = readdir($handle)) !== false ) {
        if ( $file == '.' || $file == '..' || is_dir($dir.'/'.$file) ) {
            continue;
        }
 
        if ((time() - filemtime($dir.'/'.$file)) > ($days *86400)) {
            $nofiles++;
            unlink($dir.'/'.$file);
        }
    }
    closedir($handle);
    echo "Total files deleted: $nofiles \n";
}
?>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question