Jump to content

Read Through Directory Names and Matching Based on Needle


bschultz

Recommended Posts

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 by bschultz
Link to comment
Share on other sites

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 by bschultz
Link to comment
Share on other sites

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";




}

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.