php Library
fileGrep
Keine Erläuterungen gefunden.
<?php echo "Enter characteristic string to search for:\n(If you string contains special characters mask it with \" \")\n"; $mark=trim(fread(STDIN, 1024)); $files=fileGrep($mark); echo "\nWhat shall I do with these files? [Delete/Move/Rename]\n"; $what2do=trim(fread(STDIN, 1024)); handleFiles($files,$what2do); function handleFiles($files,$what2do){ /* --------------------------- Process a collection of files. - Delte all files - Move them to new path - Rename their extension --------------------------- */ switch ($what2do){ case d: for($f=0;$f<count($files);$f++){ $string="rm -i".$files[$f]; system ($string); } #f break; case m: echo "\nEnter relative path where to move these files:\n"; $path=trim(fread(STDIN, 1024)); for($f=0;$f<count($files);$f++){ $string="mv ".$files[$f]." ".$path; system ($string); } #f break; case r: echo "\nEnter new fileextension:\n(Hopefully you have no extra dots in your filename?)\n"; $extension=trim(fread(STDIN, 1024)); for($f=0;$f<count($files);$f++){ $fname=explode(".",$files[$f]); $newName=$fname[0].".".$extension; $string="mv ".$files[$f]." ".$newName; system ($string); } #f /* ------------------- ------------------- */ break; default: echo "Nothing happend!\n"; } } function fileGrep($mark){ /* --------------------------- Select all files with some characteristic (like extension date or permissions) from -rw-r--r-- 1 arne users 24 Oct 25 09:33 index.html --------------------------- */ $execString="ls -l | grep ".$mark; exec($execString,$result); for($l=0;$l<count($result);$l++){ $words=explode(" ",$result[$l]); $filesFound[$l]=$words[count($words)-1]; } #l print_r($filesFound); return $filesFound; } ?>
Index of Library
Der gesamte Sourcecode darf gemäß GNU General Public License weiterverbreitet werden.