private void removeUselessPages(ApplicationComponent application) { if (application != null) { File ionicPagesDir = new File(ionicWorkDir,"src/pages"); List<String> pageDirectories = new ArrayList<String>(); pageDirectories.add(ionicPagesDir.getAbsolutePath()); List<PageComponent> pages = application.getPageComponentList(); for (PageComponent page : pages) { File pageDir = new File(ionicPagesDir, page.getName()); pageDirectories.add(pageDir.getAbsolutePath()); } for (File dir: FileUtils.listFilesAndDirs(ionicPagesDir, FalseFileFilter.INSTANCE, DirectoryFileFilter.DIRECTORY)) { if (!pageDirectories.contains(dir.getAbsolutePath())) { try { FileUtils.deleteDirectory(dir); } catch(Exception e) {} } } } }
/** * Get list of all existing root sub directories * * @param rootDir * - the root directory to list * @return list of sub directories */ public static Collection<File> listRootDirs(final File rootDir) { final Collection<File> dirList = new ArrayList<File>(); for (final File dir : FileUtils.listFilesAndDirs(rootDir, FalseFileFilter.INSTANCE, DirectoryFileFilter.INSTANCE)) { LOG.debug("Dir: {}", dir); // get only root directories final String name = getTemplateName(rootDir, dir); if (StringUtils.isNotBlank(name) && !name.contains("/")) { dirList.add(dir); } } return dirList; }
public void receiveFiles(TransferJob job) throws FileNotFoundException, Exception{ final String pattern = job.getSourceFilepattern(); final URI url = new URI(job.getSourceUrl()); final String path = url.getPath(); final Long fileage = 100L; Collection<File> files = FileUtils.listFiles(new File(path), new FileReceiveFilter(fileage, pattern), FalseFileFilter.INSTANCE); log.debug("{} file found for job {}",files.size(),job.getName()); for(File file : files){ log.debug("Processing: {}",file.getCanonicalPath()); queueFile(job,file); file.delete(); } }
@Override public Stamp stampOf(File directory) { if(!directory.exists()) { return new ValueStamp<>(this, -1L); } else if(!directory.isDirectory()) { throw new RuntimeException("Directory stamper cannot stamp " + directory + ", it is not a directory"); } else if(filter != null && fileStamper != null) { final Map<File, Stamp> stamps = Maps.newHashMap(); final Collection<File> files = FileUtils.listFiles(directory, filter, FalseFileFilter.INSTANCE); for(File file : files) { stamps.put(file, fileStamper.stampOf(file)); } return new ValueStamp<>(this, stamps); } else { return new ValueStamp<>(this, directory.lastModified()); } }
@Override public None build(Input input) throws IOException { requireBuild(input.origin); require(input.srcDir, new DirectoryModifiedStamper()); final Collection<File> files = FileUtils.listFiles(input.srcDir, new RegexFileFilter(input.pattern), FalseFileFilter.INSTANCE); for(File file : files) { require(file); final File dstFile = new File(input.dstDir, file.getName()); FileUtils.copyFile(file, dstFile); provide(dstFile); } return None.val; }
/** * Finds files within a given directory (and optionally its * subdirectories). All files found are filtered by an IOFileFilter. * <p> * If your search should recurse into subdirectories you can pass in * an IOFileFilter for directories. You don't need to bind a * DirectoryFileFilter (via logical AND) to this filter. This method does * that for you. * <p> * An example: If you want to search through all directories called * "temp" you pass in <code>FileFilterUtils.NameFileFilter("temp")</code> * <p> * Another common usage of this method is find files in a directory * tree but ignoring the directories generated CVS. You can simply pass * in <code>FileFilterUtils.makeCVSAware(null)</code>. * * @param directory the directory to search in * @param fileFilter filter to apply when finding files. * @param dirFilter optional filter to apply when finding subdirectories. * If this parameter is <code>null</code>, subdirectories will not be included in the * search. Use TrueFileFilter.INSTANCE to match all directories. * @return an collection of java.io.File with the matching files * @see org.apache.commons.io.filefilter.FileFilterUtils * @see org.apache.commons.io.filefilter.NameFileFilter */ public static Collection<File> listFiles( File directory, IOFileFilter fileFilter, IOFileFilter dirFilter) { if (!directory.isDirectory()) { throw new IllegalArgumentException( "Parameter 'directory' is not a directory"); } if (fileFilter == null) { throw new NullPointerException("Parameter 'fileFilter' is null"); } //Setup effective file filter IOFileFilter effFileFilter = FileFilterUtils.and(fileFilter, FileFilterUtils.notFileFilter(DirectoryFileFilter.INSTANCE)); //Setup effective directory filter IOFileFilter effDirFilter; if (dirFilter == null) { effDirFilter = FalseFileFilter.INSTANCE; } else { effDirFilter = FileFilterUtils.and(dirFilter, DirectoryFileFilter.INSTANCE); } //Find files Collection<File> files = new java.util.LinkedList<File>(); innerListFiles(files, directory, FileFilterUtils.or(effFileFilter, effDirFilter)); return files; }
/** * 查找需要合并文件的临时文件信息 * * @param directory 临时文件所在的目录 * @param prefix 临时文件的前缀 * @param caseSensitivity 临时文件的大小写敏感 * @return collection */ public static Collection<File> searchPrefixFile(File directory, String prefix, boolean caseSensitivity) { IOCase iocase = IOCase.INSENSITIVE; if (caseSensitivity) { iocase = IOCase.SENSITIVE; } //创建相关的过滤器 IOFileFilter fileFilter = FileFilterUtils.prefixFileFilter(prefix, iocase); //检查相关的过滤信息 return FileUtils.listFiles(directory, fileFilter, FalseFileFilter.INSTANCE); }
protected void setUp() throws Exception { File root1 = new File( "data/VBox" ); if( !root1.isDirectory() ) return; Collection<File> c1 = FileUtils.listFilesAndDirs ( root1, FalseFileFilter.INSTANCE, TrueFileFilter.INSTANCE ); File root2 = new File( "data/vmware" ); if( !root2.isDirectory() ) return; Collection<File> c2 = FileUtils.listFilesAndDirs ( root2, FalseFileFilter.INSTANCE, TrueFileFilter.INSTANCE ); fs = new ArrayList<File>(); fs.addAll( c1 ); fs.addAll( c2 ); }
private static List<File> getFrameworks(File appDir) { List<File> frameworks = new ArrayList<>(); File frameworkDir = new File(appDir, "Frameworks"); if (frameworkDir.exists()) { Collection<File> files = FileUtils.listFilesAndDirs(frameworkDir, FalseFileFilter.INSTANCE, FileFilterUtils.suffixFileFilter(".framework")); for (File file : files) { if (!file.equals(frameworkDir)) { frameworks.add(file); } } frameworks.addAll(FileUtils.listFiles(frameworkDir, FileFilterUtils.suffixFileFilter(".dylib"), null)); } return frameworks; }
private static void compileTLK(String path) throws IOException, InterruptedException { File dir = new File(path); System.out.println(dir); Collection<File> files = FileUtils.listFiles(dir, new SuffixFileFilter(".xml"), FalseFileFilter.FALSE); for (File file : files) { System.out.println(file.getAbsolutePath()); } for (File f : files) { ArrayList<String> commandBuilder = new ArrayList<String>(); String compilerPath = ModManager.getTankMasterTLKDir() + "MassEffect3.TlkEditor.exe"; commandBuilder.add(compilerPath); commandBuilder.add(f.getAbsolutePath()); commandBuilder.add(f.getParent() + File.separator + FilenameUtils.getBaseName(f.getAbsolutePath()) + ".xml"); commandBuilder.add("--mode"); commandBuilder.add("ToTlk"); commandBuilder.add("--no-ui"); String[] command = commandBuilder.toArray(new String[commandBuilder.size()]); //Debug stuff StringBuilder sb = new StringBuilder(); for (String arg : command) { sb.append(arg + " "); } Process p = null; System.out.println("Executing: " + sb.toString()); ProcessBuilder pb = new ProcessBuilder(command); pb.redirectErrorStream(true); p = pb.start(); p.waitFor(); } }
/** * Collects the file names in the target folder with the given filter in non recursive way. * @param folder is the target folder * @param filter is the regular expression of filtering logic * @return with the file names */ public Collection<File> listFilesWithFilter(final File folder, final String filter) { Collection<File> result; try { result = org.apache.commons.io.FileUtils.listFiles(folder, new RegexFileFilter(filter), FalseFileFilter.INSTANCE); } catch (IllegalArgumentException e) { result = logAndReturnEmptyList(folder, e); } return result; }
/** * <p>Finds files within a given directory (and optionally its * subdirectories). All files found are filtered by an IOFileFilter. * </p> * <p>If your search should recurse into subdirectories you can pass in * an IOFileFilter for directories. You don't need to bind a * DirectoryFileFilter (via logical AND) to this filter. This method does * that for you. * </p> * <p>An example: If you want to search through all directories called * "temp" you pass in <code>FileFilterUtils.NameFileFilter("temp")</code> * </p> * <p>Another common usage of this method is find files in a directory * tree but ignoring the directories generated CVS. You can simply pass * in <code>FileFilterUtils.makeCVSAware(null)</code>. * </p> * @param directory the directory to search in * @param fileFilter filter to apply when finding files. * @param dirFilter optional filter to apply when finding subdirectories. * If this parameter is null, subdirectories will not be included in the * search. Use TrueFileFilter.INSTANCE to match all directories. * @return an collection of java.io.File with the matching files * @see org.apache.commons.io.filefilter.FileFilterUtils * @see org.apache.commons.io.filefilter.NameFileFilter */ public static Collection listFiles(File directory, IOFileFilter fileFilter, IOFileFilter dirFilter) { if (!directory.isDirectory()) { throw new IllegalArgumentException("Parameter 'directory' is not a directory"); } if (fileFilter == null) { throw new NullPointerException("Parameter 'fileFilter' is null"); } //Setup effective file filter IOFileFilter effFileFilter = FileFilterUtils.andFileFilter(fileFilter, FileFilterUtils.notFileFilter(DirectoryFileFilter.INSTANCE)); //Setup effective directory filter IOFileFilter effDirFilter; if (dirFilter == null) { effDirFilter = FalseFileFilter.INSTANCE; } else { effDirFilter = FileFilterUtils.andFileFilter(dirFilter, DirectoryFileFilter.INSTANCE); } //Find files Collection files = new java.util.LinkedList(); innerListFiles(files, directory, FileFilterUtils.orFileFilter(effFileFilter, effDirFilter)); return files; }
void version32to53() { Collection folders = FileUtils.listFilesAndDirs(Storage.getRoot(), FalseFileFilter.INSTANCE, TrueFileFilter.INSTANCE); for (Object folderObject : folders) { //Search for dirs in root File folder = (File) folderObject; if (new File(folder, ".vault").exists() || !new File(folder, ".nomedia").exists()) { appendlog("\n" + folder.getAbsolutePath() + " is 5.x or not a vault, skip"); continue; //The whole thing should be skipped because vault is in 5.x standard. } appendlog("\n" + folder.getAbsolutePath() + " is pre-5.x"); Collection files = FileUtils.listFiles(folder, TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE); //walks the whole file tree, find out files that do not have encoded file names //and encode them. for (Object file : files) { File realFile = (File) file; if (".nomedia".equals(realFile.getName())) continue; String fileName = FilenameUtils.removeExtension(realFile.getName()); fileName = fileName.replace("_thumb", ""); try { Base64Coder.decodeString(fileName); } catch (IllegalArgumentException e) { String encodedFileName = Base64Coder.encodeString(fileName); fileName = realFile.getAbsolutePath().replace(fileName, encodedFileName); realFile.renameTo(new File(fileName)); } } } version53to60(); }
private List<File> getAddonJarFiles() { File addonsPath = new File(systemEnvironment.get(SystemEnvironment.ADDONS_PATH)); if (!addonsPath.exists() || !addonsPath.canRead()) { return new ArrayList<>(); } return new ArrayList<>(FileUtils.listFiles(addonsPath, new SuffixFileFilter("jar", IOCase.INSENSITIVE), FalseFileFilter.INSTANCE)); }
private void startTailers() throws FileNotFoundException { String filename = filePath.substring(filePath.lastIndexOf('/') + 1); File directory = new File(filePath.substring(0, filePath.lastIndexOf('/'))); if (!directory.exists()) { if (!directoryNotFound) { LOG.warn("Directory {} does not exist, waiting for it to be created", directory.getAbsolutePath()); directoryNotFound = true; } throw new FileNotFoundException("Directory " + directory.getAbsolutePath() + " does not exist"); } if (directoryNotFound) { LOG.warn("Directory {} created", directory.getAbsolutePath()); directoryNotFound = false; } Collection<File> files = FileUtils.listFiles( directory, new WildcardFileFilter(filename), FalseFileFilter.INSTANCE ); for (File file : files) { startTailer(file, false); } }
@Test public void shouldCheckIfDirectoryIsUpdatable() { Iterator<?> iterator = mock(Iterator.class); Matcher<IOFileFilter> matcher = new NameFilterMatcher(); when(FileUtils.iterateFiles(same(loadDirectory), same(FalseFileFilter.INSTANCE), argThat(matcher))) .thenReturn(iterator); when(iterator.hasNext()).thenReturn(true); assertTrue(loader.isUpdatable(loadDirectory)); when(iterator.hasNext()).thenReturn(false); assertFalse(loader.isUpdatable(loadDirectory)); }
private void addCustomExtensionFunctions(WebApp webApp) throws Exception { File libDir = new File(webApp.getHomeDir(), "lib"); if (!libDir.isDirectory()) { return; } List<File> classPath = new ArrayList<File>(); classPath.addAll(FileUtils.listFiles(libDir, new WildcardFileFilter("*.jar"), DirectoryFileFilter.DIRECTORY)); if (classPath.isEmpty() && !XSLWebUtils.hasSubDirectories(libDir)) { return; } classPath.add(libDir); Collection<File> saxonJars = FileUtils.listFiles(new File(Context.getInstance().getWebInfDir(), "lib"), new WildcardFileFilter("*saxon*.jar", IOCase.INSENSITIVE), FalseFileFilter.INSTANCE); classPath.addAll(saxonJars); logger.info("Initializing custom extension functions ..."); ClassFinder finder = new ClassFinder(); finder.add(classPath); ClassFilter filter = new AndClassFilter( // Must extend ExtensionFunctionDefinition class new SubclassClassFilter (ExtensionFunctionDefinition.class), // Must not be abstract new NotClassFilter (new AbstractClassFilter())); Collection<ClassInfo> foundClasses = new ArrayList<ClassInfo>(); finder.findClasses(foundClasses, filter); if (foundClasses.isEmpty()) { logger.info("No custom extension functions found."); return; } ClassLoaderBuilder builder = new ClassLoaderBuilder(); builder.add(classPath); ClassLoader classLoader = builder.createClassLoader(); for (ClassInfo classInfo : foundClasses) { String className = classInfo.getClassName(); if (initializer.isFunctionRegistered(className) || saxonJars.contains(classInfo.getClassLocation())) { continue; } Class<?> clazz = classLoader.loadClass(className); logger.info(String.format("Adding custom extension function class \"%s\" ...", className)); registerExtensionFunction((ExtensionFunctionDefinition) clazz.newInstance()); } }
private void cleanupTempFiles() { FileUtils.deleteQuietly(new File(FileUtil.TMP_PARENT_DIR)); FileUtils.deleteQuietly(new File("exploded_agent_launcher_dependencies")); // launchers extracted from old versions FileUtils.listFiles(new File("."), AGENT_LAUNCHER_TMP_FILE_FILTER, FalseFileFilter.INSTANCE).forEach(FileUtils::deleteQuietly); FileUtils.deleteQuietly(new File(new SystemEnvironment().getConfigDir(), "trust.jks")); }
@Override protected boolean isUpdatable(File directory) { NameFileFilter nameFilter = new NameFileFilter(metadataDirectoryName()); return FileUtils.iterateFiles(directory, FalseFileFilter.INSTANCE, nameFilter).hasNext(); }
/** * Returns a filter that accepts directories in addition to the {@link File} objects accepted by the given filter. * * @param dirFilter a base filter to add to * @return a filter that accepts directories */ private static IOFileFilter setUpEffectiveDirFilter(IOFileFilter dirFilter) { return dirFilter == null ? FalseFileFilter.INSTANCE : FileFilterUtils.and(dirFilter, DirectoryFileFilter.INSTANCE); }
/** * Returns a filter that accepts directories in addition to the {@link File} objects accepted by the given filter. * * @param dirFilter a base filter to add to * @return a filter that accepts directories */ private static IOFileFilter setUpEffectiveDirFilter(final IOFileFilter dirFilter) { return dirFilter == null ? FalseFileFilter.INSTANCE : FileFilterUtils.and(dirFilter, DirectoryFileFilter.INSTANCE); }