Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

File/Directory Monitor

Status
Not open for further replies.

fredmintah

Programmer
Mar 8, 2005
3
GB
Hi all,
Below is my code which is not working as I want it to work.. I need to recursively check for all files and directory under a directory and look for files or directory that has been created or edited with the day.. This code cannot read files or directories with embedded space/s. If it finds one it does not read it..
How can I make this code or php per-sey read files with embedded spaces.. Below is my code.
All suggestion and comments are welcomed..
Cheers


<?php
$checkDate = date("DdMYgiA", time());
$checkDate = $checkDate . ".xls";
$fp = fopen("D:\Frederick_Mintah\php\mmorawa\\$checkDate", "a");
$header = "File Names" . "\t" . "Date Created" . "\t" . "Date Modified" ."\n";
fwrite($fp, strtoupper($header));

echo "File Name" . "\t\t" . "Created Date" . "\t\t" . "Modified Date\n\n";

parse_dir("D:\Frederick_Mintah\php\mmorawa");

function parse_dir($scanthis)
{

$dir = @opendir($scanthis);


while (false!=($file = @readdir($dir)))
{
if ($file != "." && $file != "..")
{
$scanthispp = preg_replace("/\s/","%20",$scanthis);
$filep = preg_replace("/\s/","%20",$file);
$theFile = $scanthispp . "\\" . $filep;
$scanthispp = substr($scanthis,25); //trim absolute file path

if (is_dir($theFile))
{
parse_dir($theFile);
}

$modDate = filemtime($theFile); //get last modified date of file
$modDate = date("D d M Y g:i A", $modDate);
$creDate = filectime($theFile); //get the created date of file
$creDate = date("D d M Y g:i A", $creDate);

$checkDetails = $scanthis. "\\" . $filep . "\t " . $creDate . " \t" . $modDate ."\n";

$modDate2 = filemtime($theFile); //get last modified date of file
$modDate2 = date("D d M Y", $modDate2);
$creDate2= filectime($theFile); //get the created date of file
$creDate2 = date("D d M Y", $creDate2);

$today = date("D d M Y", time());

global $fp;

if($modDate2 == $today || $creDate2 == $today)
{
fwrite($fp, $checkDetails);
echo "\n" .$scanthis. "\\" . $filep . "\t\t " . $creDate . " \t\t" . $modDate ."\n\n";
}

}
}
}
?>
 
What OS are you running this code on?
On any *NIX type system I would just make a call to a system function:
find . -mtime -1 -ls
This lists all files that were modified in the last day.
 
I'm running this code in Windows and will be executing it in the command line.. It is working fine to some extent but cannot read files or folders with spaces in them.. I really need a help on this stuff..
 
WHat do the filenames come out as?
You are replacing the spaces with URL encoded chars. Did you try without?
Also, what is the error message you get?
 
Thanx for replying.. Actually I don't get any error.. this code is able to read files or folders without spaces in them, but it does not read files with spaces in them. The url encoded chars I placed here is just to replace the %20 with spaces. but if you think this should not be so, I'll be very glad if you can help..
About the file names; I'm using the date and time as the file name to store the results in an excel files, whether it finds a file or not.. this script also searches for any kind of file and check for the date it was created or modified.. i'll be glad if you can try this script on your system and see how it works and help me out.. I really need to work this thing out.
Thanx
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top