Posted By

cobra90nj on 11/15/08


Tagged

php file directory separator


Versions (?)

File separator


 / Published in: PHP
 

This script separates file in his directory ex. File name: test.php This script create a directory /php, and insert test.php And other extension . . .

  1. <?php
  2. /** File separator V 0.1
  3.  * by cobra90nj
  4.  * Email <cobra90nj[at]gmail[dot]com>
  5.  */
  6.  
  7. /**
  8.  * Return extension file
  9.  
  10.  * @param $dir_file Current File directory
  11.  */
  12. function extension_file($dir_file)
  13. {
  14. $path = pathinfo($dir_file);
  15. return $path["extension"];
  16. }
  17.  
  18. /**
  19.  * File separator function
  20.  
  21.  * @param $curr_dir Current directory
  22.  * @param $curr_namefile Current file name
  23.  * @param $curr_source Current extension file
  24.  */
  25. function file_separator($curr_dir, $curr_namefile, $curr_source)
  26. {
  27. if(eregi("(php|html|pl|asm|c|cpp|py|js|java|sh|rb)$", $curr_source)) {
  28.  
  29. if(!is_dir($curr_dir."/{$curr_source}_source")) {
  30. @mkdir($curr_dir."/{$curr_source}_source");
  31. }
  32.  
  33. // Inserire il nome del vostro script per evitare che si sposti anche lui
  34. if($curr_namefile != "test.php") {
  35. system("mv $curr_dir/$curr_namefile $curr_dir/{$curr_source}_source");
  36. }
  37. }
  38. }
  39.  
  40. $dir = realpath(".");
  41.  
  42. foreach (glob("*.*") as $filename) {
  43. $extension = extension_file($dir.$filename);
  44.  
  45. file_separator($dir, $filename, $extension);
  46. }
  47.  
  48. ?>

Report this snippet  

You need to login to post a comment.