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
comparing a files date script?
Moderator: General Moderators
- mydimension
- Moderator
- Posts: 531
- Joined: Tue Apr 23, 2002 6:00 pm
- Location: Lowell, MA USA
- Contact:
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
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:
any help on this would be appreciated
-webguy
Here's my code:
Code: Select all
<?php
$strWFOs = array("eax", "apx");
for ($i = 0; $i < 2; $i++)
{
//define the path
$path = "/www/datascour/". $strWFOsї$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))
{
if ($file != "." && $file != "..") //getting rid of the ".'s"
{
if (is_file($file)) //checking to see if there is a file
{
if (strpos($file, "."))
{
$strPos = strpos($file, ".");
$fileName = substr($file, 0, $strPos);
}else{
$fileName = $file;
}
$info = stat($filename);
echo date("d.M Y H:i:s", $infoї'ctime'])." - ".$fileName ."<br />";
}else{
echo "error...file does not exist!<br />";
}
clearstatcache();
}
}
//closing the directory
closedir($dir_handle);
echo "</pre>";
}
?>-webguy