简体   繁体   English

获取与名称匹配的所有子目录

[英]Get all subdirectories matching a name

I am trying to get all subdirectories that have "messages_" in the name using FileUtils 我正在尝试使用FileUtils获取名称中具有“ messages_”的所有子目录

Collection<File> filesToRead = FileUtils.listFiles(new File(fromDirectory),
        new DirectoryFileFilter() {
            @Override
            public boolean accept(File dir, String name) {
                if (dir.isDirectory() && dir.getName().contains("messages_")){
                    return true;
                }
                return false;
            }
        }, TrueFileFilter.INSTANCE);

This is not working for me. 这对我不起作用。 How to achieve this using FileUtils? 如何使用FileUtils实现这一目标?

Collection<File> filesToRead = FileUtils.listFilesAndDirs(new File(fromDirectory),
        FalseFileFilter.INSTANCE, // exclude files
        new WildcardFileFilter("*messages_*") // folders filter
);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM