Source for file FileUtil.php
Documentation is available at FileUtil.php
* Teeple2 - PHP5 Web Application Framework inspired by Seasar2
* LICENSE: This source file is subject to version 3.0 of the PHP license
* that is available through the world-wide-web at the following URI:
* http://www.php.net/license/3_0.txt. If you did not receive a copy of
* the PHP License and are unable to obtain it through the web, please
* send a note to license@php.net so we can mail you a copy immediately.
* @author Mitsutaka Sato <miztaka@gmail.com>
* @license http://www.php.net/license/3_0.txt PHP License 3.0
* include_pathからファイルを検索し、絶対パスの形で返す
* @author Hawk <scholar@hawklab.jp>
* @return String or false
foreach ($include_paths as $include_path) {
if (($realpath =
realpath($include_path .
DIRECTORY_SEPARATOR .
$path)) !==
false) {
* @param string $fileName ファイル名
$fh =
fopen($fileName, "rb");
* 途中のフォルダが存在しない場合は自動的に作成する。
* @param string $fileName ファイル名
* @param string $buf 書き込む内容
function append($fileName, $buf)
return self::write($fileName, $buf, "ab");
* 途中のフォルダが存在しない場合は自動的に作成する。
* @param string $fileName ファイル名
* @param string $buf 書き込む内容
* @param string $mode 書き込みモード
function write($fileName, $buf, $mode =
"wb")
if (!($fh =
fopen($fileName, $mode))) {
* @param mixed $dirNames 作成するディレクトリ名、またはその配列
$dirNames =
array($dirNames);
foreach($dirNames as $dir){
* 指定したディレクトリより下のディレクトリ・ファイルも
* @param mixed $dirNames 削除するディレクトリ名、またはその配列
$dirNames =
array($dirNames);
foreach($dirNames as $dir){
* 返値は配列で、最初がディレクトリの配列、次にファイルの配列となる。
* list($dirs, $files) = self::ls($dirname);
* @param string $dirName ディレクトリ名
* @return array ディレクトリとファイルの配列
$dirs =
$files =
array();
while (($file =
readdir($dh)) !==
false) {
$fullPath =
self::_addTail($dirName, DIRECTORY_SEPARATOR).
$file;
return array($dirs, $files);
* 指定したディレクトリのファイルリストを取得する
* @param string $dirName ディレクトリ名
* @param string [$regex] 取得するファイル名の正規表現
function find($dirName, $regex =
"")
$data =
self::ls($dirName);
list
($dirs, $files) =
$data;
foreach ($files as $file) {
* 指定したディレクトリのファイルリストを取得する
* @param string $dirName ディレクトリ名
* @param string [$regex] 取得するファイル名の正規表現
$data =
self::ls($dirName);
list
($dirs, $files) =
$data;
$found =
self::find($dirName, $regex);
foreach ($dirs as $dir) {
$found =
array_merge($found, self::findRecursive($dir, $regex));
* @param string $dirName ディレクトリ名
function _makeDir($dirName)
while (!@is_dir($dirName) &&
$dirName !=
DIRECTORY_SEPARATOR) {
* 指定したディレクトリ以下のファイルも自動的に削除する。
* @param string $dirName ディレクトリ名
function _removeDir($dirName)
$data =
self::ls($dirName);
list
($dirs, $files) =
$data;
foreach($files as $file){
* @param string $target 追加対象の文字列
* @param string $add 追加する文字列
function _addTail($target, $add)