Beispiel #1
0
    }
    protected function FileFilter(DirectoryIterator $pParent, DirectoryIterator $pNode)
    {
        $returnvalue = false;
        $filename = $pNode->getFilename();
        $patternDDS = '/\\.dds$/';
        $patternPNG = '/\\.png$/';
        if (preg_match($patternDDS, $filename)) {
            $returnvalue = true;
        } else {
            if (preg_match($patternPNG, $filename)) {
                $returnvalue = true;
            }
        }
        return $returnvalue;
    }
    protected function ProcessFile(DirectoryIterator $pParent, DirectoryIterator $pNode)
    {
        $oldname = $pNode->getPathname();
        $newname = $pParent->getPath() . '\\' . $this->GetLastFolderName($pParent->getPath()) . '.dds';
        rename($oldname, $newname);
        echo '<p>rename <b>' . $oldname . '</b> to <b>' . $newname . '<br/></p>';
    }
    private function GetLastFolderName($fullpath)
    {
        $folders = explode('\\', $fullpath);
        return $folders[count($folders) - 1];
    }
}
$tRenamer = new Renamer();
print $tRenamer->StartWalking('C:\\PathToFolder');
        <!-- Optional theme -->
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap-theme.min.css"
              integrity="sha384-fLW2N01lMqjakBkx3l/M9EahuwpSfeNvV63J5ezn3uZzapT0u7EYsXMjQV+0En5r" crossorigin="anonymous">

        <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
        <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
        <!--[if lt IE 9]>
        <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
        <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
        <![endif]-->
    </head>
    <body>
    <h1>Boilerplate Renamer</h1>

<?php 
$renameObject = new Renamer();
//
//$renameObject->replace_array = array(
//    'Twenty Fifteen' => 'Twenty Something',
//    'twentyfifteen' => 'twentysomething',
//    'twenty-fifteen' => 'twenty-something',
//    'twenty_fifteen' => 'twenty_something',
//    'TWENTY_FIFTEEN' => 'TWENTY_SOMETHING',
//);
/**
 * You can generate this with next three lines. Or add another search-replace items to array to the beginning or to the end, but after generation of replace array.
 */
$renameObject->search = 'Twenty Fifteen';
$renameObject->replace = 'Twenty Something';
$renameObject->generate_replace_array();
$renameObject->addIgnore('.//.git');
 /**
  * 
  * @param string $url
  * @return string
  */
 public static function absoluteURL($url, $host = null)
 {
     if (!preg_match("~^(?:f|ht)tps?://~i", $url)) {
         $url = ($host ? Renamer::absoluteURL($host) : "http://") . $url;
     }
     return $url;
 }