Example usage for org.apache.commons.vfs FileObject isHidden

List of usage examples for org.apache.commons.vfs FileObject isHidden

Introduction

In this page you can find the example usage for org.apache.commons.vfs FileObject isHidden.

Prototype

public boolean isHidden() throws FileSystemException;

Source Link

Document

Determines if this file is hidden.

Usage

From source file:org.vivoweb.harvester.util.FileAide.java

/**
 * Get a set of non-hidden direct children of the given path
 * @param path the path to search under//from  ww  w  . j a  va2  s. co m
 * @return a set of non-hidden direct children
 * @throws IOException error resolving path
 */
public static Set<String> getNonHiddenChildren(String path) throws IOException {
    Set<String> allFileListing = new HashSet<String>();
    for (FileObject file : getFileObject(path).findFiles(Selectors.SELECT_CHILDREN)) {
        if (!file.isHidden() && (file.getType() == FileType.FILE)) {
            allFileListing.add(file.getName().getBaseName());
        }
    }
    return allFileListing;
}

From source file:r.base.Files.java

/**
 * {@code list.files} produce a character vector of the names of files in the named directory.
 *
 * @param paths  a character vector of full path names; the default corresponds to the working
 *  directory getwd(). Missing values will be ignored.
 * @param pattern an optional regular expression. Only file names which match the regular
 * expression will be returned./*  www .ja  va 2s . co  m*/
 * @param allFiles  If FALSE, only the names of visible files are returned. If TRUE, all
 * file names will be returned.
 * @param fullNames If TRUE, the directory path is prepended to the file names. If FALSE,
 * only the file names are returned.
 * @param recursive Should the listing recurse into directories?
 * @param ignoreCase Should pattern-matching be case-insensitive?
 *
 * If a path does not exist or is not a directory or is unreadable it is skipped, with a warning.
 * The files are sorted in alphabetical order, on the full path if full.names = TRUE. Directories are included only if recursive = FALSE.
 *
 * @return
 */
@Primitive("list.files")
public static StringVector listFiles(@Current final Context context, final StringVector paths,
        final String pattern, final boolean allFiles, final boolean fullNames, boolean recursive,
        final boolean ignoreCase) throws IOException {

    return new Object() {

        private final StringVector.Builder result = new StringVector.Builder();
        private final RE filter = pattern == null ? null : new ExtendedRE(pattern).ignoreCase(ignoreCase);

        public StringVector list() throws IOException {
            for (String path : paths) {
                FileObject folder = context.resolveFile(path);
                if (folder.getType() == FileType.FOLDER) {
                    if (allFiles) {
                        add(folder, ".");
                        add(folder, "..");
                    }
                    for (FileObject child : folder.getChildren()) {
                        if (filter(child)) {
                            add(child);
                        }
                    }
                }
            }
            return result.build();
        }

        void add(FileObject file) {
            if (fullNames) {
                result.add(file.getName().getURI());
            } else {
                result.add(file.getName().getBaseName());
            }
        }

        void add(FileObject folder, String name) throws FileSystemException {
            if (fullNames) {
                result.add(folder.resolveFile(name).getName().getURI());
            } else {
                result.add(name);
            }
        }

        boolean filter(FileObject child) throws FileSystemException {
            if (!allFiles && isHidden(child)) {
                return false;
            }
            if (filter != null && !filter.match(child.getName().getBaseName())) {
                return false;
            }
            return true;
        }

        private boolean isHidden(FileObject file) throws FileSystemException {
            return file.isHidden() || file.getName().getBaseName().startsWith(".");
        }
    }.list();
}