0

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.

Community
  • 1
  • 1
Fahad Khan
  • 67
  • 1
  • 9
  • 2
    _"Could anyone please code the complete example"_ - **No! SO is _NOT_ a free coding service.** We can help you with your _existing_ code, but we're _NOT_ here to code it all you! You need to show us what you've tried, example of the expected out put and what out put you actually got together with any potential error messages. – M. Eriksson May 15 '17 at 04:53
  • If you need something done but you can't do it yourself, is when you _hire_ someone. I don't expect a mechanic to fix my car for free just because I don't know how to. Here are the guide lines when posting a question: [How to create a Minimal, Complete, and Verifiable example](http://stackoverflow.com/help/mcve) and also [How do I ask a good question?](http://stackoverflow.com/help/how-to-ask) – M. Eriksson May 15 '17 at 04:57
  • Looking at your question history, posting an answer will just result in you _not_ accepting it, but rather later write your own answer that you'll accept... – M. Eriksson May 15 '17 at 05:49
  • @MagnusEriksson I had read the exact same phrase on SO that I wrote here "Could anyone please code the complete example". I am failing to get the link as proof. About my history, that was a mistake and I rectified it. – Fahad Khan May 15 '17 at 06:17
  • @MagnusEriksson AND I am a software developer, not just as experienced as yourself. So I CANNOT hire anyone. This is my problem and I am asking the online community to resolve my problem. If I'm not mistaken than this is the sole purpose of SO. Or may be I am wrong here as well in your opinion? – Fahad Khan May 15 '17 at 06:18
  • 1
    The purpose of SO is to help each other with our _existing_ code, if we get stuck. Not to give people a brief and expect them to build it all for you. – M. Eriksson May 15 '17 at 06:26
  • Hi, May I have the Values that break your code? What is the mane of the file and what is the `$timeStamp_logFile` value. – Drag and Drop May 15 '17 at 06:39
  • Btw, @FahadKhan, I think that you should not get mad on SO. And try to understand Magnus point of view. 1rst this is not a free coding service, every "Write a complete working code for me" is not [on topic](http://stackoverflow.com/help/on-topic). Because those question always miss all information, show no effort and are a disrespect full toward all the community. I'm pretty sure you understand that. But your question is now Ok, you add some information and there is no more "Giv me the code". Still I feel like You still think SO is your free outsourcing website. – Drag and Drop May 15 '17 at 06:53
  • because of the **"I CANNOT hire anyone"**, so **" I am asking"** you **"to resolve my problem"** , **"If I'm not mistaken than this is"** your **"purpose"**. **"Or may be I am wrong?"** Everything in bold are copy pasta from your comment.. It's not nice.. but your question ~ok and comment are not here for discussion but for asking for clarification. So Let's work on your problem. Let's say all this is just some misunderstanding – Drag and Drop May 15 '17 at 07:02
  • @PierreLebon I have included the code in my latest edit. `$timeStamp_logFile` is just a separate variable which is used to write a log entry. – Fahad Khan May 15 '17 at 07:21
  • If it fail because the file does not exist, use [file_exists](http://php.net/manual/fr/function.file-exists.php). If the Date_time is not correct please provide the value the expected result. – Drag and Drop May 15 '17 at 07:37
  • @PierreLebon I have got the solution. The solution was giving weird syntax error while running on browser but when I ran the file using cmd it worked perfect. Now I think I should not share the solution here otherwise people would reiterate that I post a question and then answer it myself (after figuring out the solution) to help/update other visitors. – Fahad Khan May 16 '17 at 00:22
  • 1rst let me clear that a bit for you, [SelfAnswer are Great!](https://stackoverflow.blog/2011/07/01/its-ok-to-ask-and-answer-your-own-questions/). – Drag and Drop May 16 '17 at 06:08
  • And from the previous comment I will explain why Magnus talked about your history. Your [1rst Question](http://stackoverflow.com/questions/39951684/python-create-multiple-folders-from-csv-f) look like you spend time on it. But no comment nor vote on the answer, show that you kinda ignore the answer. I dont say you have to pay answer with upvote. I say by reading the question I have no idea if the issue is fixed. If the answer help, even a bit. People don't like when op vanish. – Drag and Drop May 16 '17 at 06:15
  • [2nd question](http://stackoverflow.com/questions/42475435/how-to-perform-if-statement-for-a-certain-timeperiod) is missing a lot of thing still ppl make wild quess trying to help you. But the question is clearly unclear. have 2 answers, still no answer is accepted. Here again, someone with the same issue comming to your post will have to choose witch answer is usefull by random. – Drag and Drop May 16 '17 at 06:22
  • Now, let me give you my 2Cents: You are over reacting. but doing good overal. Starting on So some time can be hard. Every time some looks mean, every time he is trying to help! Really they are trying but sometimes we get upset. One day when you have the rep(500) go to the 1rst post review queue for 1hour! And then we see if you re tilted by new user. When we feel like op is not worthy we ignored him. When there is a chance of op beeing worthy, the electrochoc must be applyed. Thats how some ppl try to help you improve. – Drag and Drop May 16 '17 at 06:30
  • Notify me when you have read all that so we can clean all those comment ourself. Because none of them make sense for future reader. – Drag and Drop May 16 '17 at 06:31
  • @PierreLebon Thanks Pierre. Understood. – Fahad Khan May 16 '17 at 08:17

0 Answers0