Current location: Hot Scripts Forums » Programming Languages » PHP » How to differenciate Newly created files from old files in a directory


How to differenciate Newly created files from old files in a directory

Reply
  #1 (permalink)  
Old 08-14-06, 04:13 AM
itssami itssami is offline
Newbie Coder
 
Join Date: Apr 2006
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
How to differenciate Newly created files from old files in a directory

I have a problem..I want to display files of a directory.And i want that newly created files are somehow highlighted from old files.
The following code (with thanks to user mab) displays files of a directory.
PHP Code:

<?php 


$dir 
'./pages/'
$handle opendir($dir); 
$file_list = array(); 

while ((
$file readdir($handle)) !== false

     if(!
in_array($file, array('.''..')) AND is_file($file)) 
     { 
           
$file_list[] = basename($file'.php'); 
     } 


closedir($handle); 

natcasesort($file_list); // do a natural sort

$file_list array_values($file_list); //reindex the array 0, 1, 2... so the following loop will work

$rows 10// how many rows in a column
$row = array(); // array to hold each row
$cnt count($file_list); // total number of files
$row_number 0;

for(
$index 0$index $cnt$index++){
    
$row[$row_number] .= "<td>".$file_list[$index]."</td>";
    
$row_number++;
    if(
$row_number >= $rows){
        
$row_number 0// reset for next column
    
}
}

$message "<table border=1>";
foreach(
$row as $value){ 
    
$message .= "<tr>";
    
$message .= $value
    
$message .= "</tr>\n";

$message .= "</table>";
echo 
$message;
?>
I want to differenciate the files which has been created within last X days..
(eg. to bold the new file names, to change color of new file names etc)
It can be done by putting this in while loop but i dont understand how to display values..
Quote:
$Diff = (time() - filectime("$path/$file"))/60/60/24;
Please help me in this problem.

Last edited by nico_swd; 08-14-06 at 04:21 AM.
Reply With Quote
  #2 (permalink)  
Old 08-14-06, 09:41 AM
infinitylimit's Avatar
infinitylimit infinitylimit is offline
Code Guru
 
Join Date: Jun 2004
Location: Oregon
Posts: 758
Thanks: 0
Thanked 0 Times in 0 Posts
Post

Not to hard, just write a check

PHP Code:

$sometimeinseconds 86400 1// 86400 seconds in a day

while (($file readdir($handle)) !== false

     if(!
in_array($file, array('.''..')) AND is_file($file)) 
     { 
          
$diff = (time() - filectime("$path/$file"))/60/60/24;
          if(
$diff $sometimeinseconds)
              
$file_list[] = array(basename($file'.php'),1);
          else
               
$file_list[] = array(basename($file'.php'),0);
     } 

Now your other function will have to be changed to work appropriately with a multi-dimentional array but basically that is the idea. You just check to see if the difference in time is greater than a certain amount of time and then call it new and mark it somehow, in this case I just used a boolean.
__________________
Hawk Enterprises -- Home to PHP games, open-source code, tutorials and free downloads
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
DIsplaying directory files alphabatically itssami PHP 1 05-13-06 02:50 PM
Directory Files - Organise? steveo PHP 3 01-27-06 09:33 PM
Print last modified date/time for files in directory MSB Perl 2 06-22-04 04:40 PM
Need Epinions-lite system in PHP & MYSQL wali001 Job Offers & Assistance 4 01-12-04 06:02 AM
php files in a cgi-bin directory epic1231 PHP 7 12-31-03 03:42 PM


All times are GMT -5. The time now is 07:26 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.