Toggle navigation
Dashboard
Dashboard Tracker
Add / Edit My Forums
System Announcements
Discussion
Active Thread Feed
Top Threads Today
Top Threads This Week
Top Threads Library
Go!
View All
View All
Login
Logout
Home
Forums Index
Server Side
/
PHP Server Side Scripting
6:24 pm Apr 28, 2026
This page requires javascript.
Forum Moderators:
coopster
Message Too Old, No Replies
deleting old files from a directory
tommy98
Msg#:4073400
12:03 pm on Feb 3, 2010
(gmt 0)
Hi there, I am trying to build a script that will delete the oldest files from a folder (keep the latest 5 files)
$count = count(glob($Dir . "*"));
if($count > 5){
// delete all old files except the newest 5
}
?
incrediBILL
Msg#:4075511
7:31 pm on Feb 6, 2010
(gmt 0)
You have to get the last modified date from each file and sort them to find the latest 5.
$last_modified = filemtime("example.txt");
jkovar
Msg#:4075651
4:09 am on Feb 7, 2010
(gmt 0)
$err = shell_exec('rm `ls -tr | head -n \'-5\'`');
tommy98
Msg#:4075684
5:20 am on Feb 7, 2010
(gmt 0)
So where abouts in the shell_exec do I specify the root folder?
Join The Conversation
Register
For Free! -
Become a
Pro Member
!
See forum categories
-
Enter the Forum
Moderators and Top Contributors
Moderator List
| Top Contributors:
This Week
,
This Month
,
Mar
,
Feb
,
Archive
,
Top 100 All Time
,
Top Voted Members
Hot Threads This Week
April 2026 Google Search Observations
what do they want?
Do you get tired of others copying your content?
AdSense Earnings and Observations - April 2026
Hello again, it's been a while
5 SEO Tips That Actually Worked for My Blog in 2026
iPhone Safari 26.4.1 errors: IPv4 & Host
I need some SEO help
Does SEO matter any more?
SEO question
Home
Forums Index
Server Side
/
PHP Server Side Scripting
6:24 pm Apr 28, 2026