|
|
|
| Title : |
Directory cleanup - This script was created for those times when you've allowed a directory to be overloaded with temp or cache type files which all need to be deleted. |
| Categories : |
PHP, Filesystem |
 Sarah King |
| Date : |
Apr 06th 2005 |
| Grade : |
3 of 5 (graded 3 times) |
| Viewed : |
10547 |
| File : |
No file for this code example. |
| Images : |
No Images for this code example. |
|
| Search : |
More code by Sarah King |
|
| Action : |
Grade This Code Example
|
|
| Tools : |
My Examples List |
|
|
|
|
|
|
|
|
|
| |
|
<?PHP
/* Directory Cleanup
* Author: Sarah King
* Date : 7 April 2005
* http://sarahk.pcpropertymanager.com/blog/directory-clean-up/29/
*
* This script was created for those times when you've allowed a
* directory to be overloaded with temp or cache type files which all
* need to be deleted. I had one so big I couldn't ftp into it!
* This script cleaned it out for me and removed 17MB of 2k files
* - you do the math!
*/
$dir2clean = 'cache';
$test = false;
$more = false;
$output = '';
if ($handle = opendir($dir2clean))
{
$header = "\n";
$i = 0;
/* This is the correct way to loop over the directory. */
while (false !== ($file = readdir($handle)) && $i < 105)
{
if ( $i < 100)
{
$output .= "<tr><td>$file</td>\n<td>";
if (substr($file, 0, 1) != '.')
{
if ($test) $output .= 'test';
elseif (unlink("{$dir2clean}/{$file}")) $output .= "deleted";
else $output .= "kept";
}
else $output .= ' ';
$output .= "</td><td>";
$output .= date ("F d Y H:i:s.", fileatime("cache/{$file}"));
$output .= "</td>\n</tr>\n";
}
else $more = true;
$i++;
}
closedir($handle);
}
?>
<html>
<head>
<?PHP
// meta refresh can fail in Internet Explorer but this works like a rocket in Firefox
if ($more && !$test)
{
echo "\n<META HTTP-EQUIV='Refresh' CONTENT=\"1; URL=http://{$_SERVER['HTTP_HOST']}{$PHP_SELF}\">\n";
}
?>
</head>
<body>
<h2>Date: <?php echo date('d-m-Y H:i'); ?><br />
Directory: <?=$dir2clean; ?><br />
Files:</h2>
<table border='1' cellpadding="4" cellspacing="0">
<?php echo $output; ?>
</table>
</body>
</html> | | |
|
| Variable serialization and unserialization. Loading and saving variable structures
to and from file. Categories : Arrays, Filesystem, Variables, Strings, PHP | | | JSON File Upload Categories : PHP, AJAX, Filesystem | | | upload function using PHP's FTP abilities. Categories : PHP, Filesystem, HTML and PHP | | | Get the correct extension and MIME types of an image, even when the filename is incorrect. Categories : PHP, Filesystem, General SQL | | | Directory TreeView - File Manager & Explorer - FTP - Utility - PHP/HTML - Categories : PHP, Directories, FTP, Filesystem, HTML and PHP | | | Kasskooye($path) tell you the complete size of a folder
Categories : PHP, Algorithms, Utilities, Filesystem | | | Email attachment code Categories : PHP, Email, Filesystem | | | a file explorer for the web, filesystem php php3 files dirs directories pictures files windows linux system list ls scripts Categories : PHP, URLs, Directories, Filesystem | | | Disk Usage, uses UNIX du command. Categories : Complete Programs, PHP, Filesystem | | | Show Source with Line Numbers Categories : PHP, Regexps, Filesystem | | | include php3 files Categories : Filesystem, PHP, Apache, Web Servers | | | grab directory listings into an array the example prints out each
subdirectory in the main dir - further work is to be performed on this one Categories : Filesystem, PHP, Directories, Search, Utilities | | | Moving folder hierarchy b/w server Categories : PHP, FTP, Filesystem | | | How to find the name of the current file? Categories : PHP, Filesystem, Strings | | | Search and Replace Text : Searches Files for Specified Text and Replaces It by a Given Text Categories : PHP, PHP Classes, Search, Filesystem | |
|
|