当前位置: 首页>>代码示例>>Java>>正文


Java FileUtils.listFilesAndDirs方法代码示例

本文整理汇总了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);
	
	}
}
 
开发者ID:ser316asu,项目名称:Reinickendorf_SER316,代码行数:38,代码来源:AgendaPanel.java

示例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;
}
 
开发者ID:paypal,项目名称:butterfly,代码行数:58,代码来源:FindFiles.java

示例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);
}
 
开发者ID:sgota,项目名称:tkcg,代码行数:10,代码来源:Generator.java


注:本文中的org.apache.commons.io.FileUtils.listFilesAndDirs方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。