-1

I want to write one PHP script that will tell me how many folders getting created today( not modified one !! ).

Ex. Suppose if gave the path ( like c:\Data ) so my script must be continuously checking that give path for if it is new entry of any folder. I have used http://php.net/manual/en/function.date-diff.php. But getting result for modified folders as well.

2 Answers2

1

Quote from @Alin Purcaru:

Use filectime. For Windows it will return the creation time, and for Unix the change time which is the best you can get because on Unix there is no creation time (in most filesystems).

Using a reference file to compare the files age allows you to detect new files whidout using a database.

// Path to the reference file. 
// All files newer than this will be treated as new
$referenceFile="c:\Data\ref";
// Location to search for new folders
$dirsLocation="c:\Data\*";

// Get modification date of reference file
if (file_exists($referenceFile))
  $referenceTime = fileatime($referenceFile);
else 
  $referenceTime = 0;

// Compare each directory with the reference file
foreach(glob($dirsLocation, GLOB_ONLYDIR) as $dir) {
  if (filectime($dir) > $referenceTime)
    echo $dir . " is new!";
}

// Update modification date of the reference file
touch($referenceFile);

Another solution could be to use a database. Any folders that are not in the database are new. This ensures to not catch modified folders.

Community
  • 1
  • 1
NeilB
  • 41
  • 5
  • fileatime returns last access time ( i.e. Modified time ). When we compare $referenceFile with $dirsLocation the if condirion becomes true and always say that this file is new .. – user2473178 Jun 28 '13 at 05:45
0

You might want to try getting your script launched with cron like every one minute and check the difference between directory lists (from before and current I mean), not the dates. It's not a perfect solution, but it will work.

Check directories arays with:

$dirs = array_filter(glob('*'), 'is_dir');

Compare them later with array_diff

Kelu Thatsall
  • 2,307
  • 1
  • 17
  • 45
  • Check how to find directories here: http://stackoverflow.com/questions/2524151/php-get-all-subdirectories-of-a-given-directory?answertab=active#tab-top And compare arrays of directories with: [array_diff](http://php.net/manual/en/function.array-diff.php) – Kelu Thatsall Jun 27 '13 at 13:43