What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Skype & Technology » Tech Talk » [SOLVED] PHP file_exists complex!

[SOLVED] PHP file_exists complex!
Author: Message:
prashker
Veteran Member
*****


Posts: 5109
Reputation: 104
– / Male / –
Joined: Mar 2005
Status: Away
O.P. [SOLVED] PHP file_exists complex!
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

This post was edited on 03-27-2010 at 07:12 PM by prashker.
03-27-2010 04:34 PM
Profile PM Find Quote Report
Mnjul
forum super mod
******

Avatar
plz wub me

Posts: 5396
Reputation: 58
– / Other / Flag
Joined: Nov 2002
Status: Away
RE: PHP file_exists complex!
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

This post was edited on 03-27-2010 at 04:49 PM by Mnjul.
03-27-2010 04:48 PM
Profile PM Web Find Quote Report
prashker
Veteran Member
*****


Posts: 5109
Reputation: 104
– / Male / –
Joined: Mar 2005
Status: Away
O.P. RE: PHP file_exists complex!
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
03-27-2010 05:30 PM
Profile PM Find Quote Report
Mnjul
forum super mod
******

Avatar
plz wub me

Posts: 5396
Reputation: 58
– / Other / Flag
Joined: Nov 2002
Status: Away
RE: PHP file_exists complex!
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']] = "";
}

03-27-2010 06:20 PM
Profile PM Web Find Quote Report
prashker
Veteran Member
*****


Posts: 5109
Reputation: 104
– / Male / –
Joined: Mar 2005
Status: Away
O.P. RE: PHP file_exists complex!
:cheesy:

You did good Mnjul (l).

Thanks again :cheesy:.
03-27-2010 07:11 PM
Profile PM Find Quote Report
« Next Oldest Return to Top Next Newest »


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On