Php tool: Search for files and execute system commands

Source: Internet
Author: User
1. match the specified keyword to find the file 2. after matching the file, execute the corresponding system command or generate a batch file. 3. feedback execution result 4. example: $ phpfind. phpd: photo.jpg, .gif, .png gmconvert-resize200X200 $ filename $ filename5. example explanation: Find all folders and subfolders under d: photo jpg, gif, png

1. match the specified keyword to find the file 2. after matching the file, execute the corresponding system command or generate a batch file. 3. feedback execution result 4. example: $ phpfind. phpd:/photo.jpg, .gif, .png gmconvert-resize200X200 $ filename 5. for example, find all the folders and subfolders under d:/photo. jpg, gif, And. png.

1. Match the specified keyword to find the file
2. After matching the file, execute the corresponding system command or generate a batch file.
3. Feedback execution results
4. Example: $ php find. php d:/photo .jpg,.gif, .png "gm convert-resize 200X200 $ filename"
5. Example explanation: Find all the folders and subfolders under d:/photo in jpg, gif, and png formats. Call GraphicsMagick to convert the size to 200*200 and overwrite the original files. <无>
  read())) {                if($currentPath[strlen($currentPath) - 1] == '/') {            $filename = $currentPath . $name;        } else {            $filename = $currentPath . '/' . $name;        }        if($name == '..' || $name == '.') {            continue;        }        if(is_dir($filename)) {            $directory[] = $filename;        } else {            str_replace(explode(',', $match), '', $name, $count);            if($match != '*' && $count == 0) {                continue;            }            $template = array('$name', '$filename', '$path', '$index');            $variable = array($name, $filename, $currentPath, $index);            $cmd = str_replace($template, $variable, $command);            if(CREATE_BAT_FILE) {                $result .= $cmd . PHP_EOL;            } else {                echo shell_exec($cmd);            }            $index++;        }    }    next($directory);}// create bat fileif(CREATE_BAT_FILE) {    $batFile = fopen('temp.bat', 'w');    fwrite($batFile, $result);    fclose($batFile);    echo 'output file to: ' . str_replace('\\', '/', __DIR__) . '/temp.bat' . PHP_EOL;}// echo result:echo $index . ' file find.' . PHP_EOL;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.