mpg Posted March 1, 2022 Share Posted March 1, 2022 What I have...hope someone can help, sorry about the messy code ill clean it up. The idea is to filter a file by first part of the filename dave mohan - song.mp3 and move only that to the target directory. //LIST FILES WITH DROPDOWN SELECTOR <?php class IgnorePathFilterIterator extends \FilterIterator { public function accept(): bool { $current = strtolower(parent::current()->getFilename()); return !in_array($current, ['thumbs.db', 'tag', 'playlist.m3u']); } } $dir = 'C:\\EZSTREAM\\smash2\\'; //$dir = '.'; $rdi = new \RecursiveDirectoryIterator($dir, \FilesystemIterator::SKIP_DOTS); $rii = new \RecursiveIteratorIterator($rdi, \RecursiveIteratorIterator::CHILD_FIRST); $iterator = new IgnorePathFilterIterator($rii); foreach($iterator as $path => $info) { if ($info->isDir()) { echo "DIR $path<br />\n"; } else { echo "FILE $path<br />\n"; } } ?> <hr> //My thingy filtering out only the dave mohan mp3 files<br> <?php $dir = ('C:\\EZSTREAM\\SMASH2\\'); $iterator = new RecursiveIteratorIterator(new \RecursiveDirectoryIterator($dir, \FilesystemIterator::SKIP_DOTS), \RecursiveIteratorIterator::CHILD_FIRST); foreach ($iterator as $filename => $fileInfo) { if ($fileInfo->isDir()) { //probally still want to use this somewhere //$ignore = Array(".", "..", "Thumbs.db" , "tag", "playlist.m3u"); } else { if (preg_match("/(\A[Dave Mohan].*.mp3)/", $fileInfo->getFileName())) { //echo $filename . '<br/>'; echo "<a href='?file=".$filename."'>$filename</a> <form action=\"removesmash2.php\" style=\"display: inline\" method=\"post\"><input type=\"hidden\" name=\"filename\" value=\"".htmlentities($curfile)."\" />"; pickstation(); echo " <input style=\"padding: 1.26em; line-height: 0.899em; height: auto\" type=\"submit\" value=\"move\" /></form> (move this song into the archive or trash)</br>\n <hr> "; } } } ?> //My problem is the removesmash2.php below throws and error I cant seem to solve... <?php //set folder to read from //$dirname = "C:\\EZSTREAM\\SMASH2\\"; $dir = ('C:\\EZSTREAM\\SMASH2\\'); $iterator = new RecursiveIteratorIterator(new \RecursiveDirectoryIterator($dir, \FilesystemIterator::SKIP_DOTS), \RecursiveIteratorIterator::CHILD_FIRST); foreach ($iterator as $filename => $fileInfo) { if ($fileInfo->isDir()) { //read files in folder //$files = scandir($dir); //ignore hidden files //$ignore = Array(".", "..", "Thumbs.db", "Playlist.m3u"); //loop through all files $moved = false; //foreach($files as $filename){ //if($filename !== $_POST['filename']) continue; foreach(stationlist() as $stationname => $path) { if($stationname !== $_POST['station']) continue; $source = $dir . $filename; $destination = $path . "\\" . $filename; echo "<h2><center>Moving from this Source: $source</h2></center><br />"; echo "<h2><center>To this Destination: $destination</h2></center><br />"; rename($source, $destination); } } ?> // for reference path selector (dropdown) looks like this <?php function stationlist() { return [ //"REASSIGN" => "C:\\XAMPP\\HTDOCS\\MPG\\RADIO\\BSP\\ASSIGNMENT", "Select Destination" => "/", //"Select Destination" => "C:\\XAMPP\\HTDOCS\\MPGRADIO\\BSP\\DAVEMOHAN", "BACKUP" => "C:\\XAMPP\\HTDOCS\\MPGRADIO\\BSP\\DAVEMOHAN\\BACKUP", "SMASH1" => "C:\\EZSTREAM\\SMASH1", "SMASH2" => "C:\\EZSTREAM\\SMASH2", "Trash it" => "C:\\BACKUP\\TRASH\\SONGS\\DAVEMOHAN", ]; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/314560-create-a-list-of-filtered-mp3-by-specific-file-name-from-directory-and-with-dropdown-move-to-another-target-directory/ Share on other sites More sharing options...
gw1500se Posted March 1, 2022 Share Posted March 1, 2022 First please use the code icon (<>) for your code and specify PHP. The formatter makes your code easier to read. Second, you forgot to give us the error message and on which line it is occurring. Quote Link to comment https://forums.phpfreaks.com/topic/314560-create-a-list-of-filtered-mp3-by-specific-file-name-from-directory-and-with-dropdown-move-to-another-target-directory/#findComment-1594141 Share on other sites More sharing options...
mpg Posted March 1, 2022 Author Share Posted March 1, 2022 Whoops for got to do that.... What I have...hope someone can help, sorry about the messy code ill clean it up. The idea is to filter a file by first part of the filename dave mohan - song.mp3 and move only that to the target directory. //LIST FILES WITH DROPDOWN SELECTOR <?php class IgnorePathFilterIterator extends \FilterIterator { public function accept(): bool { $current = strtolower(parent::current()->getFilename()); return !in_array($current, ['thumbs.db', 'tag', 'playlist.m3u']); } } $dir = 'C:\\EZSTREAM\\smash2\\'; //$dir = '.'; $rdi = new \RecursiveDirectoryIterator($dir, \FilesystemIterator::SKIP_DOTS); $rii = new \RecursiveIteratorIterator($rdi, \RecursiveIteratorIterator::CHILD_FIRST); $iterator = new IgnorePathFilterIterator($rii); foreach($iterator as $path => $info) { if ($info->isDir()) { echo "DIR $path<br />\n"; } else { echo "FILE $path<br />\n"; } } ?> <hr> //My thingy filtering out only the dave mohan mp3 files<br> <?php $dir = ('C:\\EZSTREAM\\SMASH2\\'); $iterator = new RecursiveIteratorIterator(new \RecursiveDirectoryIterator($dir, \FilesystemIterator::SKIP_DOTS), \RecursiveIteratorIterator::CHILD_FIRST); foreach ($iterator as $filename => $fileInfo) { if ($fileInfo->isDir()) { //probally still want to use this somewhere //$ignore = Array(".", "..", "Thumbs.db" , "tag", "playlist.m3u"); } else { if (preg_match("/(\A[Dave Mohan].*.mp3)/", $fileInfo->getFileName())) { //echo $filename . '<br/>'; echo "<a href='?file=".$filename."'>$filename</a> <form action=\"removesmash2.php\" style=\"display: inline\" method=\"post\"><input type=\"hidden\" name=\"filename\" value=\"".htmlentities($curfile)."\" />"; pickstation(); echo " <input style=\"padding: 1.26em; line-height: 0.899em; height: auto\" type=\"submit\" value=\"move\" /></form> (move this song into the archive or trash)</br>\n <hr> "; } } } ?> //My problem is the removesmash2.php below throws and error I cant seem to solve... <?php //set folder to read from //$dirname = "C:\\EZSTREAM\\SMASH2\\"; $dir = ('C:\\EZSTREAM\\SMASH2\\'); $iterator = new RecursiveIteratorIterator(new \RecursiveDirectoryIterator($dir, \FilesystemIterator::SKIP_DOTS), \RecursiveIteratorIterator::CHILD_FIRST); foreach ($iterator as $filename => $fileInfo) { if ($fileInfo->isDir()) { //read files in folder //$files = scandir($dir); //ignore hidden files //$ignore = Array(".", "..", "Thumbs.db", "Playlist.m3u"); //loop through all files $moved = false; //foreach($files as $filename){ //if($filename !== $_POST['filename']) continue; foreach(stationlist() as $stationname => $path) { if($stationname !== $_POST['station']) continue; $source = $dir . $filename; $destination = $path . "\\" . $filename; echo "<h2><center>Moving from this Source: $source</h2></center><br />"; echo "<h2><center>To this Destination: $destination</h2></center><br />"; rename($source, $destination); } } ?> // for reference path selector (dropdown) looks like this <?php function stationlist() { return [ //"REASSIGN" => "C:\\XAMPP\\HTDOCS\\MPG\\RADIO\\BSP\\ASSIGNMENT", "Select Destination" => "/", //"Select Destination" => "C:\\XAMPP\\HTDOCS\\MPGRADIO\\BSP\\DAVEMOHAN", "BACKUP" => "C:\\XAMPP\\HTDOCS\\MPGRADIO\\BSP\\DAVEMOHAN\\BACKUP", "SMASH1" => "C:\\EZSTREAM\\SMASH1", "SMASH2" => "C:\\EZSTREAM\\SMASH2", "Trash it" => "C:\\BACKUP\\TRASH\\SONGS\\DAVEMOHAN", ]; } ?> Parse error: syntax error, unexpected end of file in C:\xampp\htdocs\mpgradio\bsp\davemohan\removesmash2.php on line 99 Quote Link to comment https://forums.phpfreaks.com/topic/314560-create-a-list-of-filtered-mp3-by-specific-file-name-from-directory-and-with-dropdown-move-to-another-target-directory/#findComment-1594142 Share on other sites More sharing options...
gw1500se Posted March 1, 2022 Share Posted March 1, 2022 Not sure what those '\' are for but you have a missing ')' or '}' somewhere. 1 Quote Link to comment https://forums.phpfreaks.com/topic/314560-create-a-list-of-filtered-mp3-by-specific-file-name-from-directory-and-with-dropdown-move-to-another-target-directory/#findComment-1594144 Share on other sites More sharing options...
mpg Posted March 2, 2022 Author Share Posted March 2, 2022 8 hours ago, gw1500se said: Not sure what those '\' are for but you have a missing ')' or '}' somewhere. Dammed if I can see it...but im on the right track Quote Link to comment https://forums.phpfreaks.com/topic/314560-create-a-list-of-filtered-mp3-by-specific-file-name-from-directory-and-with-dropdown-move-to-another-target-directory/#findComment-1594171 Share on other sites More sharing options...
dodgeitorelse3 Posted March 2, 2022 Share Posted March 2, 2022 I don't think you need the last comma in your dropdown stationlist() function. Quote Link to comment https://forums.phpfreaks.com/topic/314560-create-a-list-of-filtered-mp3-by-specific-file-name-from-directory-and-with-dropdown-move-to-another-target-directory/#findComment-1594174 Share on other sites More sharing options...
Barand Posted March 2, 2022 Share Posted March 2, 2022 (edited) foreach ($iterator as $filename => $fileInfo) { Where is the end of that foreach loop supposed to be? Edited March 2, 2022 by Barand 1 Quote Link to comment https://forums.phpfreaks.com/topic/314560-create-a-list-of-filtered-mp3-by-specific-file-name-from-directory-and-with-dropdown-move-to-another-target-directory/#findComment-1594175 Share on other sites More sharing options...
Barand Posted March 2, 2022 Share Posted March 2, 2022 1 hour ago, dodgeitorelse3 said: I don't think you need the last comma in your dropdown stationlist() function. You're right, but it won't break anything if it is there. For eaxample <?php $a = [1,2,3,4,5,]; echo '<pre>' . print_r($a, 1) . '</pre>'; ?> outputs Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 5 ) Quote Link to comment https://forums.phpfreaks.com/topic/314560-create-a-list-of-filtered-mp3-by-specific-file-name-from-directory-and-with-dropdown-move-to-another-target-directory/#findComment-1594176 Share on other sites More sharing options...
mpg Posted March 2, 2022 Author Share Posted March 2, 2022 2 hours ago, Barand said: foreach ($iterator as $filename => $fileInfo) { Where is the end of that foreach loop supposed to be? Ah crap that worked for got to close, at least the page loads but still doesn't move the file selected......humm Quote Link to comment https://forums.phpfreaks.com/topic/314560-create-a-list-of-filtered-mp3-by-specific-file-name-from-directory-and-with-dropdown-move-to-another-target-directory/#findComment-1594178 Share on other sites More sharing options...
mpg Posted March 2, 2022 Author Share Posted March 2, 2022 Ok here is a test page if this helps. Must be something im missing in part of foreach...just not sure what.. <?php session_start(); require('rotationswitch.php'); $stationlist = stationlist(); ?> <?php ob_start();?> <html> <head> <!DOCTYPE HTML> <html> <head> <title>MPG Radio - Music for Review</title> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" /> <link rel="stylesheet" href="./assets/css/mainstation.css" /> </head> <body bgcolor="#b23c30"> <div style="background-color:white;color:black;padding:20px;"> <center><h2>Moving Selected Music</h2> <h3>Music is being moved, just a moment.</h3> </center><br> <?php //set folder to read from $dir = ('C:\\EZSTREAM\\SMASH2\\'); $iterator = new RecursiveIteratorIterator(new \RecursiveDirectoryIterator($dir, \FilesystemIterator::SKIP_DOTS), \RecursiveIteratorIterator::CHILD_FIRST); foreach ($iterator as $filename => $fileInfo) { if ($fileInfo->isDir()) { //loop through all files $moved = false; foreach(stationlist() as $stationname => $path) { if($stationname !== $_POST['station']) continue; $source = $dir . $filename; $destination = $path . "\\" . $filename; echo "<h2><center>Moving from this Source: $source</h2></center><br />"; echo "<h2><center>To this Destination: $destination</h2></center><br />"; rename($source, $destination); } } } echo "files dont move from <b>source</b> to <b>destination</b><br>"; echo "<a href='filter.php'>return for now and lets try again...</a>"; ?> </body> </html> <?php ob_flush(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/314560-create-a-list-of-filtered-mp3-by-specific-file-name-from-directory-and-with-dropdown-move-to-another-target-directory/#findComment-1594179 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.