ClarkeRubber

Place Files Into Folder of Same Name

Jun 17th, 2012
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.61 KB | None | 0 0
  1. <?php
  2. //place all video files in the current directory into a folder of same name
  3. $dir = ".";
  4.  
  5. $extensions = array("avi", "mkv", "wmv", "3gp", "mp4");
  6.  
  7. if($dh = opendir($dir)){
  8.     while(($file = readdir($dh)) !== false){
  9.         $temp = explode(".", $file);
  10.         $ext = array_pop($temp);
  11.         $file_name = implode($temp);
  12.         if(filetype($file) == "file" && in_array($ext, $extensions)){
  13.             echo "filename: $file : filetype: ".filetype($file)."\n";
  14.             if(mkdir("$file_name")){
  15.                 if(rename($file, $file_name."/".$file)){
  16.                     echo "Succesfully Moved To: $file_name / $file\n\n";
  17.                 }
  18.             }
  19.         }
  20.     }
  21.     closedir($dh);
  22. }
Advertisement
Add Comment
Please, Sign In to add comment