Shoutbox

[SOLVED] PHP file_exists complex! - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Skype & Technology (/forumdisplay.php?fid=9)
+---- Forum: Tech Talk (/forumdisplay.php?fid=17)
+----- Thread: [SOLVED] PHP file_exists complex! (/showthread.php?tid=94223)

[SOLVED] PHP file_exists complex! by prashker on 03-27-2010 at 04:34 PM

Folder Structure

/home/admin/Downloads/Downloading/Back.To.The.Future
/home/admin/Downloads/Forward.To.The.Past


php code:
//Directories to search
$monitor = array(
'/home/admin/Downloads/Downloading/',
'/home/admin/Downloads/',
'/home/admin/ThirdFolder/'
);

//Looking for $release
$release = array('Back.To.The.Future','Forward.To.The.Past','NonExistingFolder');


foreach ($monitor as $path) {
  foreach ($release as $name) {

    if (file_exists($path . $name)) {
      echo $name . ' exists in ' $path;
    }
  }
}

In my mind, I am expecting an output of


Back.To.The.Future exists in /home/admin/Downloads/Downloading/
and
Forward.To.The.Past exists in /home/admin/Downloads/

What I want to add to this code is the following
If $name does not exist in ANY of the $monitor folders, $delete[] = $name;

In which case, $delete[0] would be NonExistingFolder
RE: PHP file_exists complex! by Mnjul on 03-27-2010 at 04:48 PM

php code:
//Directories to search
$monitor = array(
'/home/admin/Downloads/Downloading/',
'/home/admin/Downloads/',
'/home/admin/ThirdFolder/'
);

//Looking for $release
$release = array('Back.To.The.Future','Forward.To.The.Past','NonExistingFolder');

>>>$delete = array_flip($release); <<<

foreach ($monitor as $path) {
  foreach ($release as $name) {

    if (file_exists($path . $name)) {
      echo $name . ' exists in ' $path;
>>>      unset($delete[$name]); <<<
    }
  }
}

>>>$delete = array_keys($delete); <<<

Dunno if it works, please try :p
RE: PHP file_exists complex! by prashker on 03-27-2010 at 05:30 PM

php code:
Array
(
    [0] => Array
        (
            [releaseid] => 1
            [name] => Back.To.The.Future
            [filesize] => 1173363271
            [files] => 26
            [creation] => 1269378095
        )

    [1] => Array
        (
            [releaseid] => 2
            [name] => Future.To.The.Past
            [filesize] => 24000
            [files] => 25
            [creation] => 1269491369
        )
}

That's what the actual format is for a $release[], so I'm not sure how array_flip will work, I assume extra work will be needed ((l))

The code works, all that needs to be done is a proper flip :p
RE: PHP file_exists complex! by Mnjul on 03-27-2010 at 06:20 PM

quote:
Originally posted by SonicSam
I assume extra work will be needed ((l))
I'll take that as "Please do it for me" :P


Maybe the following lines replacing the array_flip line would work.
php code:
foreach ($release as $release_item) {
  $delete[$release_item['name']] = "";
}

RE: PHP file_exists complex! by prashker on 03-27-2010 at 07:11 PM

:cheesy:

You did good Mnjul (l).

Thanks again :cheesy:.