code: public static void copyFolder(String sourcePath, String targetPath, final String filterName,
           final boolean recursive) throws IOException
     {
        File path = new File(targetPath);
        if (!path.exists())
        {
           if (!path.mkdirs())
              throw new IOException("outdir can't be created");
        }
        File a = new File(sourcePath);
        String[] fileNames = a.list(new FilenameFilter()
        {
           public boolean accept(File dir, String fname)
           {
              if (new File(dir, fname).isDirectory())
              {
                 return true;
              }
              else
              {
                 return fname.endsWith(filterName);
              }
           }
  
        });
        File jarFile = null;
        if (fileNames != null)
        {
           for (String fileName : fileNames)
           {
              jarFile = new File(sourcePath + File.separator + fileName);
  
              if (jarFile.isFile())
              {
                 copyFile(jarFile, targetPath);
              }
              if (recursive && jarFile.isDirectory())
              {
                 copyFolder(sourcePath + File.separator + fileName, targetPath + File.separator + fileName, filterName,
                       recursive);
              }
           }
        }
     }
docs: copy folders
  
  @param sourcePath source folder
  @param targetPath target folder
  @param filterName filter name
  @param recursive recursive boolean
  @throws IOException Thrown if an error occurs