function actionDefault() { YDDebugUtil::dump(YDPath::getDirectorySeparator(), 'getDirectorySeparator()'); YDDebugUtil::dump(YDPath::getPathSeparator(), 'getPathSeparator()'); YDDebugUtil::dump(YDPath::getVolumeSeparator(), 'getVolumeSeparator()'); YDDebugUtil::dump(YDPath::changeExtension(__FILE__, '.tpl'), 'changeExtension( __FILE__, ".tpl" )'); YDDebugUtil::dump(YDPath::getDirectoryName(__FILE__), 'getDirectoryName( __FILE__ )'); YDDebugUtil::dump(YDPath::getExtension(__FILE__), 'getExtension( __FILE__ )'); YDDebugUtil::dump(YDPath::getFileName(__FILE__), 'getFileName( __FILE__ )'); YDDebugUtil::dump(YDPath::getFileNameWithoutExtension(__FILE__), 'getFileNameWithoutExtension( __FILE__ )'); YDDebugUtil::dump(YDPath::getFilePath(__FILE__), 'getFilePath( __FILE__ )'); YDDebugUtil::dump(YDPath::getFilePathWithoutExtension(__FILE__), 'getFilePathWithoutExtension( __FILE__ )'); YDDebugUtil::dump(YDPath::getFullPath(__FILE__), 'getFullPath( __FILE__ )'); YDDebugUtil::dump(YDPath::getTempFileName(), 'getTempFileName()'); YDDebugUtil::dump(YDPath::getTempPath(), 'getTempPath()'); YDDebugUtil::dump(YDPath::hasExtension(__FILE__), 'hasExtension( __FILE__ )'); YDDebugUtil::dump(YDPath::hasExtension(YDPath::getFileNameWithoutExtension(__FILE__)), 'hasExtension( YDPath::getFileNameWithoutExtension( __FILE__ ) )'); YDDebugUtil::dump(YDPath::isAbsolute(__FILE__), 'isAbsolute( __FILE__ )'); YDDebugUtil::dump(YDPath::isAbsolute(YDPath::getFileName(__FILE__)), 'isAbsolute( getFileName( __FILE__ ) )'); YDDebugUtil::dump(YDPath::join(__FILE__), 'join( __FILE__ )'); YDDebugUtil::dump(YDPath::join(YDPath::getTempPath(), YDPath::getFileName(__FILE__)), 'join( getTempPath(), getFileName( __FILE__ ) )'); YDDebugUtil::dump(YDPath::join(YDPath::getTempPath(), __FILE__), 'join( getTempPath(), __FILE__ )'); }
/** * This function combines different file path elements to each other. * * @code * join( 'C:\temp', 'subdir', 'file.html' ) * @endcode * * results in the following path: * * @code * C:\temp\subdir\file.html * @endcode * * @returns The joined path. * * @static */ function join() { // Get the arguments for this function $args = func_get_args(); // Start with an empty path $path = ''; // Loop over the different elements foreach ($args as $arg) { if (!strlen($arg)) { continue; } // Normalize the path elements $arg = str_replace('/', YDPath::getDirectorySeparator(), $arg); $arg = str_replace('\\', YDPath::getDirectorySeparator(), $arg); // Check for an absolute path if (YDPath::isAbsolute($arg)) { $path = $arg; } else { // Remove the trailing directory separator if (substr($arg, -1, 1) == YDPath::getDirectorySeparator()) { $arg = substr($arg, 0, -1); } // Add it to the path if (strlen($path) > 0) { if (substr($arg, 0, 1) != YDPath::getDirectorySeparator()) { $path .= YDPath::getDirectorySeparator() . $arg; } else { $path .= $arg; } } else { $path .= $arg; } } } // Return the joined path return $path; }
/** * This function deletes a file or an array of files using a pattern * from the target directory. * * @param $files The file pattern or an array of file patterns * relative to the target directory. * * @returns An array with the results. */ function deleteFileByPattern($files) { if (!is_array($files)) { $files = array($files); } $res = array(); foreach ($files as $key => $pattern) { // Get the directory out of the pattern $pattern = str_replace('/', YDPath::getDirectorySeparator(), $pattern); $pattern = str_replace('\\', YDPath::getDirectorySeparator(), $pattern); $pos = strrpos($pattern, YDPath::getDirectorySeparator()); $dir = ''; if ($pos) { $dir = substr($pattern, 0, $pos + 1); $pattern = substr($pattern, $pos + 1, strlen($pattern) - $pos); } // Get the files based on the pattern $d = new YDFSDirectory(YDPath::join($this->_target_dir, $dir)); $fs = $d->getContents($pattern, '', 'YDFSFile'); // Delete the files foreach ($fs as $file) { $res = array_merge($res, $this->deleteFile(YDPath::join($dir, $file))); } } return $res; }