<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                # 文件搜索:Finder Nette \ Utils \ Finder類使瀏覽目錄結構真的很容易。 所有示例假定定義了以下類別名: ~~~ use Nette\Utils\Finder; ~~~ 搜索文件 如何在$ dir目錄中找到所有* .txt文件,而不遞歸子目錄? ~~~ foreach (Finder::findFiles('*.txt')->in($dir) as $key => $file) { echo $key; // $key is a string containing absolute filename with path echo $file; // $file is an instance of SplFileInfo } ~~~ 因此,finder返回SplFileInfo的實例。 如果目錄不存在,則拋出UnexpectedValueException。 如何在$ dir包括子目錄中搜索* .txt文件? 而不是in(),使用from(): ~~~ foreach (Finder::findFiles('*.txt')->from($dir) as $file) { echo $file; } ~~~ 通過更多的掩碼進行搜索,即使在一次迭代中的更多目錄中: ~~~ foreach (Finder::findFiles('*.txt', '*.php') ->in($dir1, $dir2) as $file) { ... } ~~~ 參數也可以是數組: ~~~ foreach (Finder::findFiles($masks)->in($dirs) as $file) { ... } ~~~ 搜索包含名稱中的數字的* .txt文件: ~~~ foreach (Finder::findFiles('*[0-9]*.txt')->from($dir) as $file) { ... } ~~~ 搜索* .txt文件,但名稱中包含“X”的文件除外: ~~~ foreach (Finder::findFiles('*.txt') ->exclude('*X*')->from($dir) as $file) { ... } ~~~ exclude()在findFiles()之后指定,因此它適用于filename。 要忽略的目錄可以使用exclude after from子句指定: ~~~ foreach (Finder::findFiles('*.php') ->from($dir)->exclude('temp', '.git') as $file) { ... } ~~~ 這里exclude()是在from()之后,因此它適用于目錄名。 現在有點復雜:搜索位于以'te'開頭而不是'temp'的子目錄中的* .txt文件: ~~~ foreach (Finder::findFiles('te*/*.txt') ->exclude('temp*/*')->from($dir) as $file) { ... } ~~~ 可以使用limitDepth()方法來限制搜索的深度。 ## 搜索目錄 除了文件,可以使用Finder :: findDirectories('subdir *')搜索目錄,或者搜索文件和目錄:Finder :: find('file.txt')。 在Nette 2.0中,掩碼僅適用于文件,而不適用于目錄。 ## 過濾 您還可以過濾結果。 例如按大小。 這樣我們將遍歷大小在100B和200B之間的文件: ~~~ foreach (Finder::findFiles('*.php')->size('>=', 100)->size('<=', 200) ->from($dir) as $file) { ... } ~~~ 或在過去兩周內更改的文件: ~~~ foreach (Finder::findFiles('*.php')->date('>', '- 2 weeks') ->from($dir) as $file) { ... } ~~~ 這里我們遍歷的行數大于1000的PHP文件。作為一個過濾器,我們使用自定義回調: ~~~ $finder = Finder::findFiles('*.php')->filter(function($file) { return count(file($file->getPathname())) > 1000; })->from($dir); ~~~ 你可以進一步擴展Nette \ Utils \ Finder類,例如使用擴展方法的維度方法: ~~~ Finder::extensionMethod('dimensions', function($finder, $width, $height){ if (!preg_match('#^([=<>!]+)\s*(\d+)$#i', $width, $mW) || !preg_match('#^([=<>!]+)\s*(\d+)$#i', $height, $mH) ) { throw new InvalidArgumentException('Invalid dimensions predicate format.'); } return $finder->filter(function($file) use ($mW, $mH) { return $file->getSize() >= 12 && ($size = getimagesize($file->getPathname())) && (!$mW || Finder::compare($size[0], $mW[1], $mW[2])) && (!$mH || Finder::compare($size[1], $mH[1], $mH[2])); }); }); ~~~ Finder,找到大于50px×50像素的圖片: ~~~ foreach (Finder::findFiles('*') ->dimensions('>50', '>50')->from($dir) as $file) { ... } ~~~ ## 連接到Amazon S3 可以使用自定義流,例如Zend_Service_Amazon_S3: ~~~ $s3 = new Zend_Service_Amazon_S3($key, $secret); $s3->registerStreamWrapper('s3'); foreach (Finder::findFiles('photos*') ->size('<=', 1e6)->in('s3://bucket-name') as $file) { echo $file; } ~~~ 方便,對吧? 你肯定會在你的應用程序中找到Finder的使用。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看