0

on Win10. here's my code. it just has to sort JSON files that got scrambled and so it does a first-field check and then move the relvant file... why won't this move the file!? all paths check out! WTH!?

$filesFolder = dirname(dirname(__FILE__));
//  returns C:\neard\www\client

$fileList = glob($filesFolder.'\\_collexion\\*.json');
$fileCounter = 0;

foreach ($fileList as $index => $reportFile) {

  $jsonFile = json_decode(file_get_contents($reportFile), true);
  $firstKey = array_key_first($jsonFile);
  $fileNameOnly = basename($reportFile);

  if ($firstValue == '5') {
    echo '---REPORT #'.$fileCounter.' FILENAME:  '.$reportFile.'<br>';
    rename($filesFolder.'\\_collexions\\'.$fileNameOnly,
           $filesFolder.'\\_collexions\\_borked\\'.$fileNameOnly);
    break;
  }
  $fileCounter++;
}

totally stumped. this should be a simple thing! what am i missing??

also: i read all the "php path not found error 3" posts on here. nothing current or useful. some so convoluted, i paled...

TIA.

WhiteRau
  • 818
  • 14
  • 32
  • 1
    Is `_borked` an existing folder? Is there already a file with the same name in the `_borked` folder? Have you checked the permissions on these folders? – KHansen Feb 26 '20 at 04:00
  • Try putting output tests throughout the code so you can see where it fails...a simple echo("got here OK") every couple of lines will help show where you have made the mistake, or test via echo ($fileList . "\n") inside the loop – Hektor Feb 26 '20 at 04:25
  • the echo right before the `rename` works just fine. there's literally nothing else to check on. the variables check out and paths, as i said, are all correct. no duplicates. so i am stumped. even the linter gives this a thumbs-up. :P – WhiteRau Feb 26 '20 at 10:28

0 Answers0