This is NOT a duplicate question as I have tried ALL of other existing solutions on Stackoverflow and after spending 5 hours I am unable to get desired result.
I want to get two (or more) newly added files from a given directory in terms of date modified. The problem is that both the files are modified at the exact same time in terms of timestamp.
The file names look like:
data_london_20170515_0900.csv
data_toronto_20170515_0900.csv
EDIT after comments from expert developers:
Before trying to implement this solution, I was simply accessing files on a certain time, that is one minute AFTER when the files are copied. (So the script was running one minute after each newly copied file using Task Scheduler)
$date=date('Ymd');
$time = date('Hi', strtotime('-1 minutes')); // 1 minute less actual server time
$date_time = $date."_".$time; // part of file name
$timeStamp_logFile = date("d/m/Y")." ".date("h:i:sa"); // DateTime used for file log entry
copy("//server/folder/data_london_".$date_time.".csv","c:/inetpub/wwwroot/folder/files/data_london_".$date_time.".csv");
copy("//server/folder/data_toronto_".$date_time.".csv","c:/inetpub/wwwroot/folder/files/data_toronto_".$date_time.".csv");
# Iterate through copied files and DB insertion
The above solution sometimes breaks because of minus one minute problem.
I have tried to implement this solution, but I was getting no output, just empty array. Also tried this solution, but same blank output.
The solution mentioned below is giving me no output:
$dir = "//server/folder/";
function scan_dir($dir) {
$ignored = array('.', '..', '.svn', '.htaccess');
$files = array();
foreach (scandir($dir) as $file) {
if (in_array($file, $ignored)) continue;
$files[$file] = filemtime($dir . '/' . $file);
}
arsort($files);
$files = array_keys($files);
return ($files) ? $files : false;
}
$f = scan_dir($dir);
print_r($f);
Any idea how to fix this problem?
Thanks.