Example usage for java.io File isHidden

List of usage examples for java.io File isHidden

Introduction

In this page you can find the example usage for java.io File isHidden.

Prototype

public boolean isHidden() 

Source Link

Document

Tests whether the file named by this abstract pathname is a hidden file.

Usage

From source file:org.atomserver.core.filestore.FileBasedContentStorage.java

/**
 * {@inheritDoc}//from  w  ww  .ja v a2 s. c  om
 */
public List<String> listCollections(String workspace) {
    List<String> collections = new ArrayList<String>();
    for (File file : pathFromRoot(workspace).listFiles(new FileFilter() {
        public boolean accept(File pathname) {
            return pathname.exists() && pathname.isDirectory() && pathname.canRead() && pathname.canWrite()
                    && !pathname.isHidden();
        }
    })) {
        collections.add(file.getName());
    }
    return collections;
}

From source file:com.aniruddhc.acemusic.player.FoldersFragment.FilesFoldersFragment.java

/**
 * Retrieves the folder hierarchy for the specified folder.
 *
 * @param dirPath The path of the new folder.
 * @param restoreState The state of the ListView that should be restored. Pass
 *                     null if the ListView's position should not be restored.
 *///from   www  .  ja v a 2 s .  co m
private void getDir(String dirPath, Parcelable restoreState) {

    ((MainActivity) getActivity()).showFolderFragmentActionItems(dirPath, getActivity().getMenuInflater(),
            ((MainActivity) getActivity()).getMenu(), mIsPasteShown);

    fileFolderNameList = new ArrayList<String>();
    fileFolderPathList = new ArrayList<String>();
    fileFolderSizeList = new ArrayList<String>();
    fileFolderTypeList = new ArrayList<Integer>();

    File f = new File(dirPath);
    File[] files = f.listFiles();

    if (files != null) {

        //Sort the files by name.
        Arrays.sort(files, NameFileComparator.NAME_INSENSITIVE_COMPARATOR);

        for (int i = 0; i < files.length; i++) {

            File file = files[i];
            if (file.isHidden() == SHOW_HIDDEN_FILES && file.canRead()) {

                if (file.isDirectory()) {

                    /*
                    * Starting with Android 4.2, /storage/emulated/legacy/...
                    * is a symlink that points to the actual directory where
                    * the user's files are stored. We need to detect the
                    * actual directory's file path here.
                    */
                    String filePath;
                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1)
                        filePath = getRealFilePath(file.getAbsolutePath());
                    else
                        filePath = file.getAbsolutePath();

                    fileFolderPathList.add(filePath);
                    fileFolderNameList.add(file.getName());
                    File[] listOfFiles = file.listFiles();

                    if (listOfFiles != null) {
                        fileFolderTypeList.add(FOLDER);
                        if (listOfFiles.length == 1) {
                            fileFolderSizeList.add("" + listOfFiles.length + " item");
                        } else {
                            fileFolderSizeList.add("" + listOfFiles.length + " items");
                        }

                    } else {
                        fileFolderTypeList.add(FOLDER);
                        fileFolderSizeList.add("Unknown items");
                    }

                } else {

                    try {
                        String path = file.getCanonicalPath();
                        fileFolderPathList.add(path);
                    } catch (IOException e) {
                        continue;
                    }

                    fileFolderNameList.add(file.getName());
                    String fileName = "";
                    try {
                        fileName = file.getCanonicalPath();
                    } catch (IOException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }

                    //Add the file element to fileFolderTypeList based on the file type.
                    if (getFileExtension(fileName).equalsIgnoreCase("mp3")
                            || getFileExtension(fileName).equalsIgnoreCase("3gp")
                            || getFileExtension(fileName).equalsIgnoreCase("mp4")
                            || getFileExtension(fileName).equalsIgnoreCase("m4a")
                            || getFileExtension(fileName).equalsIgnoreCase("aac")
                            || getFileExtension(fileName).equalsIgnoreCase("ts")
                            || getFileExtension(fileName).equalsIgnoreCase("flac")
                            || getFileExtension(fileName).equalsIgnoreCase("mid")
                            || getFileExtension(fileName).equalsIgnoreCase("xmf")
                            || getFileExtension(fileName).equalsIgnoreCase("mxmf")
                            || getFileExtension(fileName).equalsIgnoreCase("midi")
                            || getFileExtension(fileName).equalsIgnoreCase("rtttl")
                            || getFileExtension(fileName).equalsIgnoreCase("rtx")
                            || getFileExtension(fileName).equalsIgnoreCase("ota")
                            || getFileExtension(fileName).equalsIgnoreCase("imy")
                            || getFileExtension(fileName).equalsIgnoreCase("ogg")
                            || getFileExtension(fileName).equalsIgnoreCase("mkv")
                            || getFileExtension(fileName).equalsIgnoreCase("wav")) {

                        //The file is an audio file.
                        fileFolderTypeList.add(AUDIO_FILE);
                        fileFolderSizeList.add("" + getFormattedFileSize(file.length()));

                    } else if (getFileExtension(fileName).equalsIgnoreCase("jpg")
                            || getFileExtension(fileName).equalsIgnoreCase("gif")
                            || getFileExtension(fileName).equalsIgnoreCase("png")
                            || getFileExtension(fileName).equalsIgnoreCase("bmp")
                            || getFileExtension(fileName).equalsIgnoreCase("webp")) {

                        //The file is a picture file.
                        fileFolderTypeList.add(PICTURE_FILE);
                        fileFolderSizeList.add("" + getFormattedFileSize(file.length()));

                    } else if (getFileExtension(fileName).equalsIgnoreCase("3gp")
                            || getFileExtension(fileName).equalsIgnoreCase("mp4")
                            || getFileExtension(fileName).equalsIgnoreCase("3gp")
                            || getFileExtension(fileName).equalsIgnoreCase("ts")
                            || getFileExtension(fileName).equalsIgnoreCase("webm")
                            || getFileExtension(fileName).equalsIgnoreCase("mkv")) {

                        //The file is a video file.
                        fileFolderTypeList.add(VIDEO_FILE);
                        fileFolderSizeList.add("" + getFormattedFileSize(file.length()));

                    } else {

                        //We don't have an icon for this file type so give it the generic file flag.
                        fileFolderTypeList.add(FILE);
                        fileFolderSizeList.add("" + getFormattedFileSize(file.length()));

                    }

                }

            }

        }

    }

    FoldersListViewAdapter foldersListViewAdapter = new FoldersListViewAdapter(getActivity(), this,
            fileFolderNameList, fileFolderTypeList, fileFolderSizeList, fileFolderPathList);

    listView.setAdapter(foldersListViewAdapter);
    foldersListViewAdapter.notifyDataSetChanged();

    //Restore the ListView's previous state.
    if (restoreState != null) {
        listView.onRestoreInstanceState(restoreState);
    } else if (mFolderStateMap.containsKey(dirPath)) {
        listView.onRestoreInstanceState(mFolderStateMap.get(dirPath));
    }

    listView.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> arg0, View view, int index, long arg3) {

            //Store the current folder's state in the HashMap.
            if (mFolderStateMap.size() == 3) {
                mFolderStateMap.clear();
            }

            mFolderStateMap.put(currentDir, listView.onSaveInstanceState());

            String newPath = fileFolderPathList.get(index);
            if ((Integer) view.getTag(R.string.folder_list_item_type) == FOLDER)
                currentDir = newPath;

            //Check if the selected item is a folder or a file.
            if (fileFolderTypeList.get(index) == FOLDER) {
                getDir(newPath, null);
            } else {
                int fileIndex = 0;
                for (int i = 0; i < index; i++) {
                    if (fileFolderTypeList.get(i) == AUDIO_FILE)
                        fileIndex++;
                }

                play(fileFolderTypeList.get(index), fileIndex, currentDir);
            }

        }

    });

}

From source file:org.latticesoft.util.common.FileUtil.java

/**
 * Checks whethers the file is hidden or not
 * @return true if it is hidden//from   ww w .j  ava2s.co  m
 */
public static boolean isHidden(String filename) {
    boolean retVal = false;
    try {
        File f = new File(filename);
        retVal = f.isHidden();
    } catch (Exception e) {
        if (log.isErrorEnabled()) {
            log.error(e);
        }
    }
    return retVal;
}

From source file:org.cirdles.chroni.FilePickerActivity.java

/**
 * Updates the list view to the current directory
 *//*  w ww  .j  a v  a2s. c om*/
protected void refreshFilesList() {
    // sets the action bar at the top so that it tells the user what the current directory is
    actionBar = getActionBar();
    if (actionBar != null)
        actionBar.setTitle("/" + mainDirectory.getName());

    // Clear the files ArrayList
    mFiles.clear();

    // Set the extension file filter
    ExtensionFilenameFilter filter = new ExtensionFilenameFilter(acceptedFileExtensions);

    // Get the files in the directory
    File[] files = mainDirectory.listFiles(filter);
    if (files != null && files.length > 0) {
        for (File f : files) {
            if (f.isHidden() && !mShowHiddenFiles)
                // Don't add the file
                continue;

            // Add the file the ArrayAdapter IF not choosing an import directory for importFilesActivity
            if (!choosingDirectory)
                mFiles.add(f);
            else if (f.isDirectory())
                mFiles.add(f); // if choosing directory, only adds if it is a directory
        }

        Collections.sort(mFiles, new FileComparator());
    }
    mAdapter.notifyDataSetChanged();
}

From source file:org.sakaiproject.search.index.impl.SegmentInfoImpl.java

/**
 * @param f/*from  w  ww .j  a v  a  2 s  .c  om*/
 * @param message
 */
private void dumpFileInfo(File f, String message) {
    String fileInfo = message + "(" + f.getPath() + "):";
    if (!f.exists()) {
        log.error(fileInfo + " File No longer exists");

    } else {
        log.info(fileInfo + " size=[" + f.length() + "] lastModified=[" + f.lastModified() + "] read=["
                + f.canRead() + "] write=[" + f.canWrite() + "] hidden=[" + f.isHidden() + "]");
        try {
            FileInputStream fin = new FileInputStream(f);
            fin.read(new byte[4096]);
            log.info(fileInfo + " readOk");
            FileLock fl = fin.getChannel().tryLock();
            fl.release();
            fin.close();
            log.info(fileInfo + " lockOk");
        } catch (Exception ex) {
            log.warn(fileInfo + " Lock or Read failed: ", ex);
        }
    }
}

From source file:org.nuclos.client.console.NuclosConsole.java

private File testForEmptyDirectory(String sOutputDir) throws CommonBusinessException {
    final File fileOutputDir = testForDirectory(sOutputDir, true);

    for (File file : fileOutputDir.listFiles())
        if (!file.isHidden())
            throw new CommonBusinessException("The output directory must be empty.");

    return fileOutputDir;
}

From source file:org.atomserver.core.filestore.FileBasedContentStorage.java

/**
 * removes all of the files, except the file passed in
 * No more trash bin, files get deleted/*w w w  .  j av  a 2  s.com*/
 * NOTE: this method does not throw an Exception. Instead, it simply logs errors and moves on.
 *
 * @param thisRev    the file pointint at the current revision
 * @param descriptor the entry that relates to the content
 */
private void cleanupExcessFiles(final File thisRev, final EntryDescriptor descriptor) {

    String fullPath = FilenameUtils.getFullPath(thisRev.getAbsolutePath());
    File baseDir = new File(fullPath);
    if (log.isTraceEnabled()) {
        log.trace("%> cleaning up excess files at " + baseDir + " based on " + thisRev);
    }

    try {

        // get a file pointer at the previous revision of the file -- we DON'T want to delete it
        final File oneRevBack = findExistingEntryFile(descriptor, 1);

        // the set of directories to clean is the directories that contain (A) the previous
        // revision, which may or may not be the same as the current rev, and (B) the one two
        // revisions back, which may or may not be the same as the previous rev
        Set<File> directoriesToClean = new HashSet<File>(2);

        // if there was a previous rev
        if (oneRevBack != null) {
            // add it's dir to the ones to clean
            directoriesToClean.add(oneRevBack.getParentFile());
            // and if the revision is greater than 1
            if (descriptor.getRevision() > 1) {
                // then two revs back is a reasonable thing to ask for...
                File twoRevsBack = findExistingEntryFile(descriptor, 2);
                // and if it exists, add its parent to the ones to clean
                if (twoRevsBack != null) {
                    directoriesToClean.add(twoRevsBack.getParentFile());
                }
            }
        }

        // list out all of the files in the directory that are (a) files, and (b) not one of
        // the last two revisions
        for (File directoryToClean : directoriesToClean) {
            final File[] toDelete = directoryToClean.listFiles(new FileFilter() {
                public boolean accept(File fileToCheck) {

                    return fileToCheck != null && fileToCheck.exists() && fileToCheck.isFile()
                            && fileToCheck.canRead() && fileToCheck.canWrite() && !fileToCheck.isHidden()
                            && !thisRev.equals(fileToCheck)
                            && (oneRevBack == null || !oneRevBack.equals(fileToCheck));

                }
            });

            // if there's anything to delete...
            if (toDelete != null && toDelete.length > 0) {

                for (File file : toDelete) {

                    //delete the file
                    if (log.isTraceEnabled()) {
                        log.trace("deleting file" + file.getName());
                    }

                    FileUtils.forceDelete(file);
                }
                cleanUpToCollection(descriptor, directoryToClean);
            }
        }
    } catch (Exception e) {
        // if there was any exception in the move (including the one we might have just thrown
        // above) then we should log it
        log.error("Error when cleaning up dir [" + baseDir + "] when writing file (" + thisRev + ")", e);
    }
}

From source file:org.saiku.repository.ClassPathRepositoryManager.java

private List<IRepositoryObject> getRepoObjects(File root, List<String> fileType, String username,
        List<String> roles, boolean includeparent) throws Exception {
    List<IRepositoryObject> repoObjects = new ArrayList<IRepositoryObject>();
    ArrayList<File> objects = new ArrayList<>();
    if (root.isDirectory()) {

        this.listf(root.getAbsolutePath(), objects);

    } else {/* ww  w  .j a va2  s  .  c  o  m*/
        objects = new ArrayList<>();
        objects.add(root);
    }

    Acl2 acl = new Acl2(root);
    acl.setAdminRoles(userService.getAdminRoles());

    for (File file : objects) {

        if (!file.isHidden()) {
            String filename = file.getName();
            String relativePath = file.getPath().substring(getDatadir().length() - 3, file.getPath().length());
            relativePath = relativePath.replace("\\", "/");

            if (acl.canRead(relativePath, username, roles)) {
                List<AclMethod> acls = acl.getMethods(new File(relativePath), username, roles);
                if (file.isFile()) {
                    if (!fileType.isEmpty()) {
                        for (String ft : fileType) {
                            if (!filename.endsWith(ft)) {
                                continue;
                            }
                            String extension = FilenameUtils.getExtension(file.getPath());

                            repoObjects.add(new RepositoryFileObject(filename, "#" + relativePath, extension,
                                    relativePath, acls));
                        }

                    }

                }
                if (file.isDirectory()) {
                    repoObjects.add(new RepositoryFolderObject(filename, "#" + relativePath, relativePath, acls,
                            getRepoObjects(file, fileType, username, roles, false)));
                }
                Collections.sort(repoObjects, new Comparator<IRepositoryObject>() {

                    public int compare(IRepositoryObject o1, IRepositoryObject o2) {
                        if (o1.getType().equals(IRepositoryObject.Type.FOLDER)
                                && o2.getType().equals(IRepositoryObject.Type.FILE))
                            return -1;
                        if (o1.getType().equals(IRepositoryObject.Type.FILE)
                                && o2.getType().equals(IRepositoryObject.Type.FOLDER))
                            return 1;
                        return o1.getName().toLowerCase().compareTo(o2.getName().toLowerCase());

                    }

                });
            }
        }
    }
    //}
    return repoObjects;
}

From source file:com.mindquarry.desktop.workspace.SVNSynchronizer.java

/**
 * This removes the need for calling svn del and svn add manually. It also
 * automatically adds hidden files (such as Thumbs.db on Windows or
 * .something) to the ignore list.// w  ww  .  j  ava 2s  .c o  m
 */
private void deleteMissingAndAddUnversioned(File base) throws ClientException, IOException {
    for (Status s : getLocalChanges(base)) {
        log.debug("deleting/adding/ignoring " + SVNSynchronizer.textStatusDesc(s.getTextStatus()) + " "
                + nodeKindDesc(s.getNodeKind()) + " <->" + " "
                + SVNSynchronizer.textStatusDesc(s.getRepositoryTextStatus()) + " "
                + nodeKindDesc(s.getReposKind()) + " '" + wcPath(s) + "'");

        if (s.getTextStatus() == StatusKind.missing) {
            // Note: a missing element could either be an already versioned
            // element or something that was just added. The added variant
            // cannot be diagnosed without asking the server for status
            // information.
            Status remoteStatus = client.singleStatus(s.getPath(), true);
            long remoteRev = -1;
            if (s.getNodeKind() == NodeKind.dir) {
                // getReposLastCmtRevisionNumber() does not properly work
                // with files:
                remoteRev = remoteStatus.getReposLastCmtRevisionNumber();
            } else {
                // getLastChangedRevisionNumber() does not properly work
                // with directories:
                remoteRev = remoteStatus.getLastChangedRevisionNumber();
            }

            if (remoteRev < 0) {
                log.debug("missing item that was locally added: " + s.getPath());

                // locally added -> undo add
                client.revert(s.getPath(), true);
            } else {
                log.debug("missing item that is already versioned (delete now): " + s.getPath() + ", nodeKind: "
                        + s.getNodeKind());

                // already versioned -> delete

                if (s.getNodeKind() == NodeKind.dir) {
                    // we must remove each single file or folder inside dir
                    // (and dir itself) because simply deleting the top dir
                    // will let all subfiles and folders in the 'missing'
                    // state - and upon update they would be re-added, which
                    // is not what we want. We want the missing directory
                    // to be turned into a deleted one without any of the
                    // real dir or files inside be left over because this
                    // would confuse the user

                    log.debug("deleting all subfiles/folders of directory '" + s.getPath() + "':");
                    // this is a status() method with a new parameter
                    // 'showMissing' that will include all subdirs and
                    // subfiles that are below the missing dir
                    Status[] localStati = client.status(s.getPath(), true, false, true, false, false, true);
                    for (Status status : localStati) {
                        client.remove(new String[] { status.getPath() }, null, true);
                    }

                    // Normally, client.remove doesn't delete the directory,
                    // but leaves the empty directory structure behind.
                    // However, since we call this function when refreshing
                    // the workspace changes, empty directories that are
                    // left behind will confuse the user, so we need to make
                    // sure it's really gone. We can reconstruct it later
                    // using our shallow working copy.
                    File dir = new File(s.getPath());
                    if (dir.exists()) {
                        FileUtils.deleteDirectory(dir);
                    }
                } else {

                    // if the first parameter would be an URL, it would do a
                    // commit (and use the second parameter as commit message) -
                    // but we use a local filesystem path here and thus we only
                    // schedule for a deletion
                    client.remove(new String[] { s.getPath() }, null, true);
                }
            }

        } else if (s.getTextStatus() == StatusKind.unversioned) {
            // set standard to-be-ignored files
            File file = new File(s.getPath());
            if (file.isHidden()) {
                log.debug("unversioned item is hidden (ignore now): " + s.getPath());

                // update the svn:ignore property by appending a new line
                // with the filename to be ignored (on the parent folder!)
                PropertyData ignoreProp = client.propertyGet(file.getParent(), PropertyData.IGNORE);

                if (ignoreProp == null) { // create ignore property
                    client.propertyCreate(file.getParent(), PropertyData.IGNORE, file.getName(), false);
                } else { // merge ignore property
                    ignoreProp.setValue(mergeIgnoreProperty(ignoreProp, file.getName()), false);
                }
            } else {
                log.debug("unversioned item (add now): " + s.getPath());

                // TODO: check for new files that have the same name when
                // looking at it case-insensitive (on unix systems) to avoid
                // problems when checking out on Windows (eg. 'report' is
                // the same as 'REPORT' under windows, but not on unix).
                // for this to work we simply check if there is a file with
                // the same case-insensitive name in this folder, exclude it
                // from the add and give a warning message to the user
                // TODO: check for special filename chars (eg. ";" ":" "*")
                // that are not cross-platform

                // otherwise we turn all unversioned into added
                // Do not recurse, we do that ourselve below; we need to
                // look at each file individually because we want to ignore
                // some - setting the recurse flag here would add all files
                // and folders inside the directory
                client.add(s.getPath(), false);

                // For directories, we recurse into it: the reason is that
                // we need to re-retrieve the stati for that directory after
                // it has been added, because all the unversioned children
                // are not part of the initial stati list (when the dir is
                // unversioned). Note: we cannot use isNodeKind() == 'dir'
                // because svn sees it as 'none' at this point
                if (new File(s.getPath()).isDirectory()) {
                    deleteMissingAndAddUnversioned(new File(s.getPath()));
                } else {
                    // For files, we guess the MIME type and set it as a
                    // property. This allows the server to provide more
                    // specific options, such as showing images inline
                    // and displaying more suitable icons for files.
                    // Also, if the svn:mime-type property is
                    // set, then the Subversion Apache module will use its
                    // value to populate the Content-type: HTTP header when
                    // responding to GET requests.
                    String mimeType = MimeTypeUtilities.guessMimetype(s.getPath());
                    log.debug("Setting mime type for " + s.getPath() + ": " + mimeType);
                    client.propertyCreate(s.getPath(), "svn:mime-type", mimeType, false);
                    if (mimeType.startsWith("text/")) {
                        // Causes the file to contain the EOL markers that
                        // are native to the operating system on which
                        // Subversion was run. Subversion will actually
                        // store the file in the repository using normalized
                        // LF EOL markers.
                        client.propertyCreate(s.getPath(), "svn:eol-style", "native", false);
                    }
                }
            }
        }
    }
}

From source file:org.traccar.web.server.model.DataServiceImpl.java

private File getMonthFile(File baseFolder, int month) {
    File monthFile = null;//from   w  w w  . ja  v a2  s  . c o  m
    if (baseFolder != null && baseFolder.isDirectory()) {
        File[] files = baseFolder.listFiles();
        if (files != null && files.length > 0) {
            for (File file : files) {
                String fileMonth = file.getName().split("_")[1];
                try {
                    if (Integer.parseInt(fileMonth) == month && !file.isHidden()
                            && !file.getName().endsWith("~fglg ,hl,khlg'[4" + "lkn")) {
                        monthFile = file;
                        break;
                    }
                } catch (NumberFormatException ignored) {

                }
            }
        }
    }
    return monthFile;
}