本文整理汇总了Java中org.apache.commons.io.FileUtils.listFilesAndDirs方法的典型用法代码示例。如果您正苦于以下问题:Java FileUtils.listFilesAndDirs方法的具体用法?Java FileUtils.listFilesAndDirs怎么用?Java FileUtils.listFilesAndDirs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.io.FileUtils
的用法示例。
在下文中一共展示了FileUtils.listFilesAndDirs方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: scanDirectoriesAtFolderChosen
import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
/**
* Scans sub directories associated with the target 'src' folder, lists them into dirsList
* @throws IOException
*
*/
public static synchronized void scanDirectoriesAtFolderChosen(JFileChooser jfc, Path dir, ConcurrentHashMap<String, String> holdValueToKey, WatchService watcher) throws IOException{//JFileChooser jfc, Path dir
File f = new File(jfc.getSelectedFile().getAbsolutePath());
if(f.isDirectory()){
//System.out.println("Is a directory: "+jfc.getSelectedFile().getAbsolutePath());
File rFile = new File(jfc.getSelectedFile().getAbsolutePath());
SuffixFileFilter extFilter = new SuffixFileFilter("java");
Collection filesListUtil = FileUtils.listFilesAndDirs(rFile,extFilter,TrueFileFilter.INSTANCE); //get utils for files in subdir, looks for .java files as well
ArrayList<File> filesList = new ArrayList<File>();
ArrayList<File> dirsList = new ArrayList<File>();
for(java.util.Iterator fileIter = filesListUtil.iterator();fileIter.hasNext();){ //iterate through filesListUtil subdirs, add to filesList to be watched
File currentF = (File) fileIter.next();
//System.out.println("Reading Paths from: "+currentF.getAbsolutePath());
if(!(currentF.isDirectory())){
filesList.add(currentF); //add each file while iterating through subdirectories
}else{
dirsList.add(currentF); //add each dir to watch
}
}
/**
* File system traversal
*/
System.out.println("WatchService: DirectoriesList length = "+dirsList.size());
//System.out.println("FilesListUtil length: "+filesListUtil.size());
fileSystemTraversal(dirsList, dir, watcher, holdValueToKey);
}
}
示例2: execution
import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
@Override
protected TUExecutionResult execution(File transformedAppFolder, TransformationContext transformationContext) {
final File searchRootFolder = getAbsoluteFile(transformedAppFolder, transformationContext);
String _pathRegex = pathRegex;
if (pathRegex != null && File.separatorChar != '/') {
_pathRegex = pathRegex.replace('/', File.separatorChar);
}
final String normalizedPathRegex = _pathRegex;
IOFileFilter filter = new AbstractFileFilter() {
public boolean accept(File file) {
if ((file.isFile() && !includeFiles) || (file.isDirectory() && !includeFolders)) {
return false;
}
if (nameRegex != null && !file.getName().matches(nameRegex)) {
return false;
}
if (normalizedPathRegex != null) {
String relativePath = getRelativePath(searchRootFolder, file.getParentFile());
if (!relativePath.matches(normalizedPathRegex)) {
return false;
}
}
return true;
}
};
Collection<File> files = new ArrayList<>();
if (includeFiles) {
files = FileUtils.listFiles(searchRootFolder, filter, (recursive ? TrueFileFilter.INSTANCE : null));
}
if (includeFolders) {
Collection<File> folders = new ArrayList<>();
Collection<File> allFolders = FileUtils.listFilesAndDirs(searchRootFolder, new NotFileFilter(TrueFileFilter.INSTANCE), (recursive ? TrueFileFilter.INSTANCE : DirectoryFileFilter.DIRECTORY));
allFolders.remove(searchRootFolder);
for (File folder : allFolders) {
if (!recursive && !folder.getParentFile().equals(searchRootFolder)) {
continue;
}
if (filter.accept(folder)) {
folders.add(folder);
}
}
files.addAll(folders);
}
TUExecutionResult result = null;
if(files.size() == 0) {
result = TUExecutionResult.warning(this, "No files have been found", new ArrayList<File>(files));
} else {
result = TUExecutionResult.value(this, new ArrayList<File>(files));
}
return result;
}
示例3: getTemplateDirectoryFiles
import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
/**
* 获取模板目录所有文件列表和目录.
*
* @param directory the directory
* @return the file list
*/
private Collection<File> getTemplateDirectoryFiles(File directory) {
return FileUtils.listFilesAndDirs(directory, TrueFileFilter.INSTANCE, DirectoryFileFilter.INSTANCE);
}