function find_in_dir($dir = '', $change_file_name = 0, $svn_file, $head_path, $svn_path) { $info = array(); $files = array(); //扫描目录整体发布 if (empty($dir)) { echo "\$dir 变量不能为空!"; exit; } else { $files = scandir($dir); $fh = fopen($svn_file, "a"); foreach ($files as $v) { if ($v == '.' || $v == '..' || $v == '.hg' || $v == '.hgignore' || $v == '.svn' || $v == 'dev' || $v == 'font' || stripos($v, '.fla')) { continue; } $file = $dir . '/' . $v; if (is_dir($file)) { $dd_file = str_replace("\\", "/", $file); $ttfile = explode($head_path, $dd_file); $info[$ttfile[1]] = find_in_dir($file, $change_file_name, $svn_file, $head_path, $svn_path); } else { chdir($dir); $xfile = str_replace(")", '\\)', $file); $xfile = str_replace("(", '\\(', $xfile); exec("svn log --limit 1 " . $xfile, $arr); if (!empty($arr)) { $infos = explode("|", $arr[1]); $infos[0] = substr($infos[0], 1); $ss_file = str_replace("\\", "/", $file); $fileinfo = pathinfo($file); $new_file = $fileinfo['dirname'] . '/' . $fileinfo['filename'] . '.' . $fileinfo['extension'] . '_' . trim($infos[0]); $new_file = str_replace($svn_path, $head_path, $new_file); //更新update log file $data = $fileinfo['dirname'] . '/' . $fileinfo['filename'] . '.' . $fileinfo['extension'] . "\t" . trim($infos[0]) . "\n"; $data = str_ireplace($svn_path, "", $data); fwrite($fh, $data); $nnew_file = str_replace("\\", "/", $new_file); chdir($fileinfo['dirname']); //压缩文件 condenseRes($v, $nnew_file); $info[$ss_file] = trim($v); } $arr = array(); } } // end foreach fclose($fh); } return $info; }
/** * Finds a path to a target file, checking the filename and each directory * name in the path case-insensitively. If a target file is found, returns * the path with the correct, existing casing. Otherwise, returns false. * Optionally searches for files with the same name but alternative * extensions (defaults to true). Optionally searches for only files * ($findDir = 0), files and directories ($findDir = 1), or only * directories ($findDir = 2) * * @param string $path The file to search for. * @param bool $findAltExtensions Set false for strict extension checking. * @param int $findDir Set 0 to only return paths to actual files, * Set 1 to return paths to both files and directories * Set 2 to only return paths to directories * @return string|bool */ function fileExists($path, $findAltExt = true, $findDir = 1) { // This function is expecting valid path names. // So, if you need to trim or remove bad characters, // do that before sending them to this function // guard against bad input (such as a null path) $findDir = (int) $findDir; // 0: no, 1: yes, 2: only $path = (string) $path; if ($path === '') { return false; } // efficiency checks if (is_file($path)) { if ($findDir < 2) { return $path; } elseif (!$findAltExt) { return false; } } if (is_dir($path)) { if ($findDir > 0) { return $path; } elseif (!$findAltExt) { return false; } } // -convert Windows directory separators '\' to standard '/' // -remove unneeded path elements, such as '.' or 'dir/../' // -remove trailing slash // -trim each component // -this is so we can explode by '/' and correctly identify // each path components (e.g., 'one' and 'two' from 'one\two') $path = cleanPath($path); $path = explode('/', $path); // if they only supplied a single component, there is the unlikely // case that they are searching for the root directory // Let's check for that, before assuming that they are looking for // a file or directory in the current working directory if (count($path) === 1) { $absDir = convertAbsoluteDir($path[0]); if ($absDir !== false) { // in this case, we have an absolute path of a root directory if ($findDir === 0) { return false; } else { // this will give them the actual root directory for this OS return $absDir; } } else { // in this case, just try to find a relative target return find_in_dir('.', $path[0], $findAltExt, $findDir); } } // we are going to search for the final component a bit differently, // since it can be either a directory or a file, so lets pull that off $finalComponent = array_pop($path); // now we need to find the directory portion of the path // if is_dir() cannot find it, then we will start pulling off // components from the end of the path until we get a directory // we can locate $dirsNotFound = array(); while (!is_dir(implode('/', $path))) { // for the first dir, check if its an absolute or relative dir if (count($path) === 1) { $absDir = convertAbsoluteDir($path[0]); if ($absDir !== false) { // if absolute, set the starting path to the actual root $path = array($absDir); } else { $dirsNotFound[] = array_pop($path); } break; // checking first dir, can't go back any more } else { // move last dir in $path to start of $dirsNotFound $dirsNotFound[] = array_pop($path); } } $dirsNotFound = array_reverse($dirsNotFound); // correct order of dirs // if $path is empty, not even the first dir could be identified // so, we will assume its a relative path // otherwise, we are going to use what we could if ($path === array()) { $baseDir = '.'; } else { $baseDir = implode('/', $path); } // now lets do a case-insensitive search for the rest of the dirs foreach ($dirsNotFound as $targetDir) { // use find_in_dir, but only search for dirs $search = find_in_dir($baseDir, $targetDir, false, 2); if ($search === false) { return false; } $baseDir .= '/' . $search; } // Huzzah! At this point, we should have found our directory, // and we just need to search for the final component $finalSearch = find_in_dir($baseDir, $finalComponent, $findAltExt, $findDir); if ($finalSearch === false) { return false; } else { $existingPath = $baseDir . '/' . $finalSearch; if (substr($existingPath, 0, 2) === './') { $existingPath = substr($existingPath, 2); } return $existingPath; } }