bschultz Posted July 16, 2018 Share Posted July 16, 2018 (edited) I'm trying to loop through a directory for subdirectory names. If a subdirectory matches needle and haystack...loop through that directory and proceed. Here's the code $this_show_date = media_shooter_date ("Saturday", "Saturday"); $path = "/showdownloads/MediaShooter/MediaShooterDrop/"; $dir = new DirectoryIterator("/showdownloads/MediaShooter/MediaShooterDrop/"); foreach ($dir as $fileinfo) { echo "$fileinfo\n"; if ($fileinfo->isDir() && !$fileinfo->isDot()) { if (strpos($fileinfo->getFilename(), "Years of Hits") !== false && strpos($fileinfo->getFilename(), "{$this_show_date}") !== false && strpos($fileinfo->getFilename(), 'revised') !== false) { $final_directory = $fileinfo->getFilename(); // does this match ALL of the following: Years of Hits, the date returned from $this_show_date AND contains the word REVISED } elseif (strpos($fileinfo->getFilename(), "Years of Hits") !== false && strpos($fileinfo->getFilename(), "{$this_show_date}") !== false && strpos($fileinfo->getFilename(), 'revised') !== true) { $final_directory = $fileinfo->getFilename(); // does this match ALL of the following: Years of Hits, the date returned from $this_show_date AND DOES NOTcontain the word REVISED } } } echo $final_directory; exit; // once $final_directory is set, the code will proceed By echoing the $filename, I get this: Pulse Best 07.16.18 3 for KKBJ-FM only Sonrise (CHR) SUNDAY BEFORE 3PM 07.14.18 6 for KKBJ-FM only 25 Years of Hits SATURDAY 1 07.21.18 1 for WMIS-FM only Virtual News Network MF 07.16.18 3 for WBJI-FM only SSI RMWorldTravel Minute 07.16.18 4 for KKBJ-AM only Rick Jackson's Cntry Clsscs (3hr) SATURDAY 07.14.18 3 for KPMI-AM only Monsters of Rock 3 (Sun) 07.15.18 1 for WMIS-FM only JT John Tesh Weekday 07.16.18 8 for KKBJ-FM only Live In Concert ROCK (Sunday) AFTER 3PM 07.15.18 4 for WMIS-FM only Slow Jams Sunday Nite pop 07.15.18 5 for KKBJ-FM only . SSI Chuck Woolery Minute 07.16.18 for KPMI-AM only Racing Rocks! (Crnt) SATURDAY 07.14.18 3 for WMIS-FM only 25 Years of Hits SATURDAY WITH REVISED HOUR 2 SEGMENT 1 07.21.18 1 for WMIS-FM only Red Cup Country 5 07.14.18 1 for WBJI-FM only .. House of Hair 3 SATURDAY 07.14.18 2 for WMIS-FM only PHP Notice: Undefined variable: final_directory in /cron/shows/25-years.php on line 62 This should match 25 Years of Hits SATURDAY 1 07.21.18 1 for WMIS-FM only and 25 Years of Hits SATURDAY WITH REVISED HOUR 2 SEGMENT 1 07.21.18 1 for WMIS-FM only...but doesn't. Any ideas why? Thanks! Edited July 16, 2018 by bschultz Quote Link to comment Share on other sites More sharing options...
requinix Posted July 16, 2018 Share Posted July 16, 2018 strpos is case-sensitive. You can use stripos if that's a problem. Quote Link to comment Share on other sites More sharing options...
bschultz Posted July 17, 2018 Author Share Posted July 17, 2018 Changing the code to replace strpos with stripos still didn't match anything. Quote Link to comment Share on other sites More sharing options...
requinix Posted July 17, 2018 Share Posted July 17, 2018 Have you confirmed $this_show_date has the value you think it does? What's your code now? Quote Link to comment Share on other sites More sharing options...
bschultz Posted July 17, 2018 Author Share Posted July 17, 2018 (edited) I have confirmed the date is correct... Here's the code: $this_show_date = media_shooter_date ("Saturday", "Saturday"); echo "This show date = $this_show_date\n"; /* // This is the old code...that does NOT check for the date $dir = "/showdownloads/MediaShooter/MediaShooterDrop/*Years\ of\ Hits*"; foreach(glob($dir) as $file) { $files = glob("$file/*.*"); foreach($files as $audio){ $file_to_go = str_replace($file,"",$audio); copy($audio, '/showdownloads/25Years/' . $file_to_go); } } */ $path = "/showdownloads/MediaShooter/MediaShooterDrop/"; $dir = new DirectoryIterator("/showdownloads/MediaShooter/MediaShooterDrop/"); foreach ($dir as $fileinfo) { //echo "$fileinfo\n"; if ($fileinfo->isDir() && !$fileinfo->isDot()) { if (stripos($fileinfo->getFilename(), "Years of Hits") !== false && stripos($fileinfo->getFilename(), "{$this_show_date}") !== false && stripos($fileinfo->getFilename(), 'revised') !== false) { $final_directory = $fileinfo->getFilename(); } elseif (stripos($fileinfo->getFilename(), "Years of Hits") !== false && stripos($fileinfo->getFilename(), "{$this_show_date}") !== false && stripos($fileinfo->getFilename(), 'revised') === false) { $final_directory = $fileinfo->getFilename(); } } } echo $final_directory; exit; $files = glob("/showdownloads/MediaShooter/MediaShooterDrop/$final_directory/*.*"); foreach($files as $audio){ $file_to_go = str_replace($file,"",$audio); copy($audio, '/showdownloads/25Years/' . $file_to_go); } Edited July 17, 2018 by bschultz Quote Link to comment Share on other sites More sharing options...
requinix Posted July 17, 2018 Share Posted July 17, 2018 The date is the only thing I can't see, so I think it's the part that's wrong. What is its exact value? Quote Link to comment Share on other sites More sharing options...
bschultz Posted July 17, 2018 Author Share Posted July 17, 2018 This show date = 07.21.18 Quote Link to comment Share on other sites More sharing options...
bschultz Posted July 17, 2018 Author Share Posted July 17, 2018 Here's the function... function media_shooter_date ($show, $date_of_directory) // show is daily or weekend...date of directory is the date to expect from the media shooter directory { $todays_dow = date('l'); // Sunday, Monday...etc if ($show == "daily" && $todays_dow == "Sunday") { $media_shooter_date_diff = "+1 day"; } if ($show == "daily" && $todays_dow == "Monday") { $media_shooter_date_diff = "+0 day"; } if ($show == "daily" && $todays_dow == "Tuesday") { $media_shooter_date_diff = "-1 day"; } if ($show == "daily" && $todays_dow == "Wednesday") { $media_shooter_date_diff = "-2 days"; } if ($show == "daily" && $todays_dow == "Thursday") { $media_shooter_date_diff = "-3 days"; } if ($show == "daily" && $todays_dow == "Friday") { $media_shooter_date_diff = "-4 days"; } if ($show == "daily" && $todays_dow == "Saturday") { $media_shooter_date_diff = "-5 days"; } if ($show == "Saturday" && $todays_dow == "Sunday") { $media_shooter_date_diff = "+6 days"; } if ($show == "Saturday" && $todays_dow == "Monday") { $media_shooter_date_diff = "+5 days"; } if ($show == "Saturday" && $todays_dow == "Tuesday") { $media_shooter_date_diff = "+4 days"; } if ($show == "Saturday" && $todays_dow == "Wednesday") { $media_shooter_date_diff = "+3 days"; } if ($show == "Saturday" && $todays_dow == "Thursday") { $media_shooter_date_diff = "+2 days"; } if ($show == "Saturday" && $todays_dow == "Friday") { $media_shooter_date_diff = "+1 day"; } if ($show == "Saturday" && $todays_dow == "Saturday") { $media_shooter_date_diff = "+0 day"; } if ($show == "Sunday" && $todays_dow == "Sunday") { $media_shooter_date_diff = "+0 day"; } if ($show == "Sunday" && $todays_dow == "Monday") { $media_shooter_date_diff = "+6 days"; } if ($show == "Sunday" && $todays_dow == "Tuesday") { $media_shooter_date_diff = "+5 days"; } if ($show == "Sunday" && $todays_dow == "Wednesday") { $media_shooter_date_diff = "+4 days"; } if ($show == "Sunday" && $todays_dow == "Thursday") { $media_shooter_date_diff = "+3 days"; } if ($show == "Sunday" && $todays_dow == "Friday") { $media_shooter_date_diff = "+2 day"; } if ($show == "Sunday" && $todays_dow == "Saturday") { $media_shooter_date_diff = "+1 day"; } return date('m.d.y', strtotime("$media_shooter_date_diff")). "\n"; } Quote Link to comment Share on other sites More sharing options...
requinix Posted July 17, 2018 Share Posted July 17, 2018 Look carefully. return date('m.d.y', strtotime("$media_shooter_date_diff")). "\n"; Quote Link to comment Share on other sites More sharing options...
bschultz Posted July 17, 2018 Author Share Posted July 17, 2018 New line! Damn! Thank you. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.