Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6377119
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:49:50+00:00 2026-05-25T01:49:50+00:00

I have a folder with this structure mainFolder –Sub1 –File .scl –File .awl –Other

  • 0

I have a folder with this structure

mainFolder

   --Sub1  
         --File .scl
         --File .awl
         --Other files
   --Sub2  
         --Files
   --Sub3
   --Sub4

I want to copy it to another location but i want the Sub3 to be avoided and (depending from the situation) some file from the Sub1

Here is an extract from what i did so far:

FileUtils.copyDirectory(srcDir, dstDir, new FileFilter() {
        public boolean accept(File pathname) {
            // We don't want 'Sub3' folder to be imported
            // + look at the settings to decide if some format needs to be
            // excluded
            String[] ignoreList= new String[]{
                    !Settings.getSiemensOptionAWL() ? ".awl":"uselessStringWilNeverBeFound",
                    !Settings.getSiemensOptionSCL() ? ".scl":"uselessStringWilNeverBeFound",
                    "Sub3"
            };

            return !(ignoreFile(pathname, ignoreList) && pathname
                    .isDirectory());
        }
    }, true);


    public static boolean ignoreFile(File file, String[] ignoreList) {
        for (final String ignoreStr : ignoreList)
            if (file.getAbsolutePath().contains(ignoreStr))
                return true;
        return false;
    }

Apparently it seams to work. But i think is a very ugly solution….
Does anyone knows a better way?

P.S:
of course Settings.getSiemensOptionAWL() is just boolean function taht return my decision

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T01:49:50+00:00Added an answer on May 25, 2026 at 1:49 am

    The other options suggested here are good, however another alternative is to nest multiple simpler FileFilters together (which may be overkill, of course!)

    public class FailFastFileFilter implements FileFilter {
        protected final List<FileFilter> children = new ArrayList<FileFilter>();
    
        public FailFastFileFilter(FileFilter... filters) {
            for (FileFilter filter: filters) {
                if (filter != null)
                    this.filters.add(filter);
            }       
        }
    
        public boolean accept(File pathname) {
            for (FileFilter filter: this.filters) {
                if (!filter.accept(pathname)) {
                    return false; // fail on the first reject
                }
            }
    
            return true;
        }
    }
    

    Then simply combine short, concise FileFilters for the Sub3 case, the .scl and the .awl case. The example FailFastFileFilter I’ve shown above would let you specify null as one of the filters (so you could use inline if statements to determine whether particular FileFilters are applied)

    For the sake of completion, here’s a general idea of how I’d implement the child filters for the Sub1 cases and the Sub3 case.

    First, a filter to excluding files with a particular extension within a directory:

    public class ExcludeExtensionInDirFileFilter implements FileFilter {
        protected final String parentFolder;
        protected final String extension;
    
        public ExtensionFileFilter(String parentFolder, String extension) {
            this.parentFolder = parentFolder;
            this.extension = extension.toLowerCase();
        }
    
        public boolean accept(File file) {
            if (!file.isDirectory() && file.getParentFile().getName().equalsIgnoreCase(parentFolder))
                return !file.getAbsolutePath().toLowerCase().endsWith(extension);
            else
                return true;
        }
    }
    

    Then to exclude a directory:

    public class ExcludeDirFileFilter implements FileFilter {
        protected final String name;
    
        public ExcludeDirFileFilter(String name) {
            this.name = name.toLowerCase();
        }
    
        public boolean accept(File file) {
            if (file.isDirectory() && file.getName().equalsIgnoreCase(name))
                return false;
            else
                return true;
        }
    }
    

    Setting up the FailFastFileFilter would then look something like:

    FileFilter filters = new FailFastFileFilter(
        new ExcludeDirFileFilter("Sub3"), // always exclude Sub3
        (!Settings.getSiemensOptionAWL() ? new ExcludeExtensionInDirFileFilter("Sub1",".awl"), null), // Exclude Sub1/*.awl if desired
        (!Settings.getSiemensOptionSCL() ? new ExcludeExtensionInDirFileFilter("Sub1",".scl"), null) // Exclude Sub1/*.scl if desired
    );
    
    FileUtils.copyDirectory(srcDir, dstDir, filters);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a folder structure like this: /some_folder /tmp /tmp/foo /tmp/foo/fu * /tmp/bar /tmp/bar/bah
I have a folder structure like this: /articles .index.php .second.php .third.php .fourth.php If I'm
If I have a folder structure set up like this: ~/Projects emacs package1 package1-helpers
If I have a folder structure that looks like this: / /bin/myComponent.cfc /reports/index.cfm How
Say I have this url: http://site.example/dir/ In this folder I have these files: test.ascx.cs
I've discovered this folder in C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files and have a few questions. What
I have some folder with different files. I want to use something like this:
I have this folder structure: /www/project/web/app.php I can access it via /project/web/index.php . The
I have this folder structure: package/ __init__.py misc/ __init__.py tools.py subpackage/ __init__.py submodule.py I
I have this massive folder structure with thousands of folders and subfolders. I need

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.