public static void visitFilesRecursively(FileVisitor visitor, File directory, String filePattern, String directoryPattern, boolean recursively) {
		if (!directory.isDirectory()) directory = directory.getParentFile();
		if (!directory.getName().matches(directoryPattern)) return;
		visitor.visitDirectory(directory);
		final ArrayList<File> childDirectories = new ArrayList<File>();
		for (File file : directory.listFiles()) {
			if (file.isDirectory()) {
				childDirectories.add(file);
			} else if (file.isFile()) {
				if (!file.getName().matches(filePattern)) continue;
				visitor.visitFile(file);
			}
		}
		if (recursively) {
			for (File childDirectory : childDirectories) {
				visitFilesRecursively(visitor, childDirectory, filePattern, directoryPattern, recursively);
			}
		}
	}