Dr. Arne JachensDr. Arne Jachens

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

1globals.php
2readData.php
3XML_readFile.php
4fraktal.php
5fileGrep.php
6XML_extractTag.php
7writeNamedData.php
8readXmlFile.php
9readNamedData.php
10XML_findAllElements.php
11readFromStdIn.php
12plotResult.php
13dtaus.php
14pdf.php
15fitData.php
16XML_extractElement.php
17readFilenames.php
18writeData.php
19genDTAUS.php
20closeFigures.php
21XML_extractAttribute.php
22enumerateFiles.php
23db.php
24polynominalFit.php
25LaTeXbrief.php
26hex2dec.php

Der gesamte Sourcecode darf gemäß GNU General Public License weiterverbreitet werden.