/** * Delete all the contents of a directory. * * @param Directory|string $dir Directory instance or directory path as a string to delete the contents from. * @param resource $context [optional] See the unlink() function for documentation. * * @return int * * @see unlink() */ public static function deleteContents($dir, $context = null) { // Convert the directory into a path string, return the $default value if failed if (($dir = self::asPath($dir, false)) === null) { return -1; } // The directory must exist if (!self::isDirectory($dir)) { return -1; } // Count the deleted files, symbolic links and directories $count = 0; // Create a directory scanner, then list and delete all directory contents $scanner = new DirectoryScanner($dir); while (($item = $scanner->read()) !== null) { $count += self::delete($item, $context, true); } // Return the number of removed files and directories return $count; }
/** * Get all language files in the language directory. * * @return array Language files. * * @throws Exception Throws if an error occurred. */ private static function getLanguageFiles() { // Get the language directory and make sure it exists $langDir = static::getLanguageDirectory(); if (!$langDir->isDirectory()) { throw new Exception('Language file directory doesn\'t exist, or isn\'t accessible!'); } // Create a directory scanner to list all language files $scanner = new DirectoryScanner($langDir); // Define an array for the language files $langFiles = array(); // Process each file in this directory while (($file = $scanner->read()) !== null) { // Make sure this file is a file if (!$file->isFile()) { continue; } // Make sure the extension is valid if (!StringUtils::equals($file->getExtension(false), 'ini', false, true)) { continue; } // Add the file to the language files list $langFiles[] = $file; } // Return the list of files return $langFiles; }