Page 1 of 1

comparing a files date script?

Posted: Tue Dec 31, 2002 2:03 pm
by webguy
hello-

anyone have a script handy that will take a file passed to it, get the date of the file's creation and compare it vs. the current date?

I'm developing on a win98 box, but the script will run on a linux box.

basicaly I want to check a dir, and each file in it. then get the date of the file's creation compare it to the current date, the return valued of them being compared will be compared to a value stored in a db.

Any hints or clues on what functions I should check out or if anyone has a script similar to this already written, that would be great help to me.

thanks for your time!

- webguy

Posted: Thu Jan 02, 2003 10:21 am
by webguy
justa bump... :D

Posted: Thu Jan 02, 2003 5:47 pm
by mydimension
i don't believe you can get the creation date for a file (someone feel free to correct me if im wrong). the closet function that would seem to suit your purpose is the stat() function: http://www.php.net/manual/en/function.stat.php

Posted: Fri Jan 03, 2003 8:19 am
by webguy
yeah I'm using the stat() function. but the problem I'm running into know is the date that is being returned is the date of a directory where the .php file is being run from. I added a is_file() check and it says I'm not getting any files for some reason. Although I can print out the names of the files, etc.

Here's my code:

Code: Select all

<?php 
$strWFOs = array("eax", "apx");
for ($i = 0; $i < 2; $i++)
&#123;
  //define the path
  $path = "/www/datascour/". $strWFOs&#1111;$i] ."/";
  //using the opendir function
  $dir_handle = @opendir($path) or die("Unable to open $path");
  echo "<pre>";
  echo "Directory Listing of $path\n";
  echo "<br /><br />\n";
  //running the while loop
  while ($file = readdir($dir_handle)) 
  &#123;
	  if ($file != "." && $file != "..") //getting rid of the ".'s"
	  &#123;
		  if (is_file($file)) //checking to see if there is a file
			  &#123;
				  if (strpos($file, "."))
				  &#123;
					$strPos =	strpos($file, ".");
					$fileName = substr($file, 0, $strPos); 
				  &#125;else&#123;
					$fileName = $file;
				  &#125;
				  $info = stat($filename);
				  echo date("d.M Y H:i:s", $info&#1111;'ctime'])." - ".$fileName ."<br />";
		      &#125;else&#123;
				  echo "error...file does not exist!<br />";
			  &#125;
		  clearstatcache();
		&#125;
	&#125;
  //closing the directory
  closedir($dir_handle);
  echo "</pre>";
&#125;
?>
any help on this would be appreciated

-webguy