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:br.com.thinkti.android.filechooserfrag.fragFileChooser.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
    View v = info.targetView;/*ww  w  .  j a  va  2s .com*/
    final Option o = adapter.getItem((int) info.id);
    switch (item.getItemId()) {
    case R.id.mnuDelete:
        String msg = String.format(getString(R.string.txtReallyDelete), o.getName());
        if (lib.ShowMessageYesNo(_main, msg, _main.getString(R.string.question)) == lib.yesnoundefined.yes) {
            try {
                File F = new File(o.getPath());
                boolean delete = false;
                if (F.exists()) {
                    if (F.isDirectory()) {
                        String[] deleteCmd = { "rm", "-r", F.getPath() };
                        Runtime runtime = Runtime.getRuntime();
                        runtime.exec(deleteCmd);
                        delete = true;
                    } else {
                        delete = F.delete();
                    }
                }

                if (delete)
                    adapter.remove(o);

            } catch (Exception ex) {
                lib.ShowMessage(_main, ex.getMessage(), getString((R.string.Error)));
            }
        }
        //lib.ShowToast(_main,"delete " + t1.getText().toString() + " " + t2.getText().toString() + " " + o.getData() + " "  + o.getPath() + " " + o.getName());
        //editNote(info.id);
        return true;
    case R.id.mnuRename:
        String msg2 = String.format(getString(R.string.txtRenameFile), o.getName());
        AlertDialog.Builder A = new AlertDialog.Builder(_main);
        final EditText inputRename = new EditText(_main);
        A.setMessage(msg2);
        A.setTitle(getString(R.string.rename));

        // Specify the type of input expected; this, for example, sets the input as a password, and will mask the text
        inputRename.setInputType(InputType.TYPE_CLASS_TEXT);
        inputRename.setText(o.getName());
        A.setView(inputRename);
        A.setPositiveButton(_main.getString(R.string.ok), new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                String name = inputRename.getText().toString();
                final String pattern = ".+\\.(((?i)v.{2})|((?i)k.{2})|((?i)dic))$";
                Pattern vok = Pattern.compile(pattern);
                if (lib.libString.IsNullOrEmpty(name))
                    return;
                if (vok.matcher(name).matches()) {
                    try {

                        File F = new File(o.getPath());
                        File F2 = new File(F.getParent(), name);
                        if (!F2.exists()) {
                            final boolean b = F.renameTo(F2);
                            if (b) {
                                o.setName(name);
                                o.setPath(F2.getPath());
                                adapter.notifyDataSetChanged();
                            }
                        } else {
                            lib.ShowMessage(_main, getString(R.string.msgFileExists), "");
                        }

                    } catch (Exception ex) {
                        lib.ShowMessage(_main, ex.getMessage(), getString((R.string.Error)));
                    }
                } else {
                    AlertDialog.Builder A = new AlertDialog.Builder(_main);
                    A.setPositiveButton("OK", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {

                        }
                    });
                    A.setMessage(getString(R.string.msgWrongExt2));
                    A.setTitle(getString(R.string.message));
                    AlertDialog dlg = A.create();
                    dlg.show();

                }
            }
        });
        A.setNegativeButton(_main.getString(R.string.cancel), new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {

            }
        });
        AlertDialog dlg = A.create();
        dlg.show();
        return true;
    case R.id.mnuCopy:
        _copiedFile = (o.getPath());
        _cutFile = null;
        return true;
    case R.id.mnuCut:
        _cutFile = (o.getPath());
        _cutOption = o;
        _copiedFile = null;
        return true;
    case R.id.mnuPaste:
        if (_cutFile != null && _copiedFile != null)
            return true;
        String path;
        File F = new File(o.getPath());
        if (F.isDirectory()) {
            path = F.getPath();
        } else {
            path = F.getParent();
        }
        if (_copiedFile != null) {
            File source = new File(_copiedFile);
            File dest = new File(path, source.getName());
            if (dest.exists()) {
                lib.ShowMessage(_main, getString(R.string.msgFileExists), "");
                return true;
            }
            String[] copyCmd;
            if (source.isDirectory()) {
                copyCmd = new String[] { "cp", "-r", _copiedFile, path };
            } else {
                copyCmd = new String[] { "cp", _copiedFile, path };
            }
            Runtime runtime = Runtime.getRuntime();
            try {
                runtime.exec(copyCmd);
                Option newOption;
                if (dest.getParent().equalsIgnoreCase(currentDir.getPath())) {
                    if (dest.isDirectory() && !dest.isHidden()) {
                        adapter.add(new Option(dest.getName(), getString(R.string.folder),
                                dest.getAbsolutePath(), true, false, false));
                    } else {
                        if (!dest.isHidden())
                            adapter.add(new Option(dest.getName(),
                                    getString(R.string.fileSize) + ": " + dest.length(), dest.getAbsolutePath(),
                                    false, false, false));
                    }
                }
            } catch (Exception ex) {
                lib.ShowMessage(_main, ex.getMessage(), getString((R.string.Error)));
            }

        } else if (_cutFile != null) {
            File source = new File(_cutFile);
            File dest = new File(path, source.getName());
            if (dest.exists()) {
                lib.ShowMessage(_main, getString(R.string.msgFileExists), "");
                return true;
            }
            String[] copyCmd;
            if (source.isDirectory()) {
                copyCmd = new String[] { "mv", "-r", _cutFile, path };
            } else {
                copyCmd = new String[] { "mv", _cutFile, path };
            }
            Runtime runtime = Runtime.getRuntime();
            _cutFile = null;
            try {
                runtime.exec(copyCmd);
                Option newOption;
                try {
                    adapter.remove(_cutOption);
                    _cutOption = null;
                } catch (Exception e) {

                }
                if (dest.getParent().equalsIgnoreCase(currentDir.getPath())) {
                    if (dest.isDirectory() && !dest.isHidden()) {
                        adapter.add(new Option(dest.getName(), getString(R.string.folder),
                                dest.getAbsolutePath(), true, false, false));
                    } else {
                        if (!dest.isHidden())
                            adapter.add(new Option(dest.getName(),
                                    getString(R.string.fileSize) + ": " + dest.length(), dest.getAbsolutePath(),
                                    false, false, false));
                    }
                }
            } catch (Exception ex) {
                lib.ShowMessage(_main, ex.getMessage(), getString((R.string.Error)));
            }
        }
        return true;
    case R.id.mnuNewFolder:
        A = new AlertDialog.Builder(_main);
        //final EditText input = new EditText(_main);
        final EditText inputNF = new EditText(_main);
        A.setMessage(getString(R.string.msgEnterNewFolderName));
        A.setTitle(getString(R.string.cmnuNewFolder));

        // Specify the type of input expected; this, for example, sets the input as a password, and will mask the text
        inputNF.setInputType(InputType.TYPE_CLASS_TEXT);
        inputNF.setText("");
        A.setView(inputNF);
        A.setPositiveButton(_main.getString(R.string.ok), new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                String name = inputNF.getText().toString();
                if (lib.libString.IsNullOrEmpty(name))
                    return;
                String NFpath;
                File NF = new File(o.getPath());
                if (NF.isDirectory()) {
                    NFpath = NF.getPath();
                } else {
                    NFpath = NF.getParent();
                }
                try {
                    File NewFolder = new File(NFpath, name);
                    NewFolder.mkdir();
                    adapter.add(new Option(NewFolder.getName(), getString(R.string.folder),
                            NewFolder.getAbsolutePath(), true, false, false));

                } catch (Exception ex) {
                    lib.ShowException(_main, ex);
                }
            }
        });
        A.setNegativeButton(_main.getString(R.string.cancel), new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {

            }
        });
        dlg = A.create();
        dlg.show();
        return true;
    default:
        return super.onContextItemSelected(item);
    }
}

From source file:org.lnicholls.galleon.server.Server.java

private void createAppClassLoader() {
    ArrayList urls = new ArrayList();
    File directory = new File(System.getProperty("apps"));
    if (directory.exists()) {
        // TODO Handle reloading; what if list changes?
        File[] files = directory.listFiles(new FileFilter() {
            public final boolean accept(File file) {
                return !file.isDirectory() && !file.isHidden() && file.getName().toLowerCase().endsWith(".jar");
            }/*  w w  w.  j a v  a2s .  c o  m*/
        });
        if (files != null) {
            for (int i = 0; i < files.length; ++i) {
                try {
                    URL url = files[i].toURI().toURL();
                    urls.add(url);
                    log.debug("Found app: " + url);
                } catch (Exception ex) {
                    // should never happen
                }
            }
        }
    }

    directory = new File(System.getProperty("hme"));
    if (directory.exists()) {
        // TODO Handle reloading; what if list changes?
        File[] files = directory.listFiles(new FileFilter() {
            public final boolean accept(File file) {
                return !file.isDirectory() && !file.isHidden() && file.getName().toLowerCase().endsWith(".jar");
            }
        });
        if (files != null) {
            for (int i = 0; i < files.length; ++i) {
                try {
                    URL url = files[i].toURI().toURL();
                    urls.add(url);
                    log.debug("Found HME app: " + url);
                } catch (Exception ex) {
                    // should never happen
                }
            }
        }
    }

    mAppClassLoader = new URLClassLoader((URL[]) urls.toArray(new URL[0]));
}

From source file:org.lnicholls.galleon.server.Server.java

public List getSkins() {
    File skinsDirectory = new File(System.getProperty("skins"));
    if (skinsDirectory.isDirectory() && !skinsDirectory.isHidden()) {
        File[] files = skinsDirectory.listFiles(new FileFilter() {
            public boolean accept(File pathname) {
                return pathname.getName().endsWith(".gln"); // Galleon skins
            }/*w  ww. ja va  2s.  c om*/
        });
        return Arrays.asList(files);
    }

    return new ArrayList();
}

From source file:org.jini.commands.files.FindFiles.java

/**
 * Find Files with a wild card pattern//  ww  w  .  j  a v a  2 s  .c om
 *
 * @param dirName
 * @param wildCardPattern
 * @param recursive
 */
void findFilesWithWildCard(String dirName, String wildCardPattern, boolean recursive) {

    PrintChar printChar = new PrintChar();
    printChar.setOutPutChar(">");

    if ((this.getJcError() == false) && (this.isDir(dirName) == false)) {
        this.setJcError(true);
        this.addErrorMessages("Error : Directory [" + dirName + "] does not exsist.");
    }

    if (this.getJcError() == false) {
        printChar.start();

        try {
            File root = new File(dirName);

            Collection files = FileUtils.listFiles(root, null, recursive);

            TablePrinter tableF = new TablePrinter("Name", "Type", "Readable", "Writable", "Executable",
                    "Size KB", "Size MB", "Last Modified");

            for (Iterator iterator = files.iterator(); iterator.hasNext();) {

                File file = (File) iterator.next();

                if (file.getName().matches(wildCardPattern)) {

                    if (this.withDetails == false) {
                        System.out.println(file.getAbsolutePath());
                    } else {

                        java.util.Date lastModified = new java.util.Date(file.lastModified());
                        long filesizeInKB = file.length() / 1024;
                        double bytes = file.length();
                        double kilobytes = (bytes / 1024);
                        double megabytes = (kilobytes / 1024);

                        String type = "";

                        DecimalFormat df = new DecimalFormat("####.####");

                        if (file.isDirectory()) {
                            type = "Dir";
                        }
                        if (file.isFile()) {
                            type = "File";
                        }

                        if (file.isFile() && file.isHidden()) {
                            type = "File (Hidden)";
                        }
                        if (file.isDirectory() && (file.isHidden())) {
                            type = "Dir (Hidden)";
                        }

                        String canExec = "" + file.canExecute();
                        String canRead = "" + file.canRead();
                        String canWrite = "" + file.canWrite();
                        String filesizeInKBStr = Long.toString(filesizeInKB);
                        String filesizeInMBStr = df.format(megabytes);

                        tableF.addRow(file.getAbsolutePath(), type, canRead, canWrite, canExec, filesizeInKBStr,
                                filesizeInMBStr, lastModified.toString());
                    }
                }
            }

            if (this.withDetails == true) {
                if (files.isEmpty() == false) {
                    tableF.print();
                }
            }

            printChar.setStopPrinting(true);
        } catch (Exception e) {

            this.setJcError(true);
            this.addErrorMessages("Error : " + e.toString());
        }

    }

    printChar.setStopPrinting(true);
    this.done = true;
}

From source file:org.lnicholls.galleon.server.Server.java

public List getWinampSkins() {
    File skinsDirectory = new File(System.getProperty("root") + "/media/winamp");
    if (skinsDirectory.isDirectory() && !skinsDirectory.isHidden()) {
        File[] files = skinsDirectory.listFiles(new FileFilter() {
            public boolean accept(File pathname) {
                return pathname.getName().endsWith(".wsz"); // Winamp skins
            }/*w ww.  j a v  a2  s. c o m*/
        });
        return Arrays.asList(files);
    }

    return new ArrayList();
}

From source file:org.apache.ode.bpel.engine.ProcessAndInstanceManagementImpl.java

/**
 * Generate document information elements for a set of files.
 *
 * @param docinfo/*  www .  ja va  2  s  .com*/
 *            target element
 * @param files
 *            files
 * @param recurse
 *            recurse down directories?
 */
private void genDocumentInfo(TProcessInfo.Documents docinfo, File[] files, boolean recurse) {
    if (files == null)
        return;
    for (File f : files) {
        if (f.isHidden())
            continue;

        if (f.isDirectory()) {
            if (recurse)
                genDocumentInfo(docinfo, f.listFiles(), true);
        } else if (f.isFile()) {
            genDocumentInfo(docinfo, f);
        }
    }
}

From source file:projetg2.DcmSnd.java

public void addFile(File f) {
    if (f.isDirectory()) {
        File[] fs = f.listFiles();
        if (fs == null || fs.length == 0)
            return;
        for (int i = 0; i < fs.length; i++)
            addFile(fs[i]);//from w w  w.  j a  va 2 s .  c o  m
        return;
    }

    if (f.isHidden())
        return;

    FileInfo info = new FileInfo(f);
    DicomObject dcmObj = new BasicDicomObject();
    DicomInputStream in = null;
    try {
        in = new DicomInputStream(f);
        in.setHandler(new StopTagInputHandler(Tag.StudyDate));
        in.readDicomObject(dcmObj, PEEK_LEN);
        info.tsuid = in.getTransferSyntax().uid();
        System.out.println("tsuid  " + in.getTransferSyntax().uid());
        info.fmiEndPos = in.getEndOfFileMetaInfoPosition();
    } catch (IOException e) {
        e.printStackTrace();
        System.err.println("WARNING: Failed to parse " + f + " - skipped.");
        System.out.print('F');
        return;
    } finally {
        CloseUtils.safeClose(in);
    }
    info.cuid = dcmObj.getString(Tag.MediaStorageSOPClassUID, dcmObj.getString(Tag.SOPClassUID));
    if (info.cuid == null) {
        System.err.println("WARNING: Missing SOP Class UID in " + f + " - skipped.");
        System.out.print('F');
        return;
    }
    info.iuid = dcmObj.getString(Tag.MediaStorageSOPInstanceUID, dcmObj.getString(Tag.SOPInstanceUID));
    if (info.iuid == null) {
        System.err.println("WARNING: Missing SOP Instance UID in " + f + " - skipped.");
        System.out.print('F');
        return;
    }
    if (suffixUID != null)
        info.iuid = info.iuid + suffixUID[0];
    addTransferCapability(info.cuid, info.tsuid);
    files.add(info);
    System.out.print('.');
}

From source file:mod.org.dcm4che2.tool.DcmSnd.java

public void addFile(File f) {
    if (f.isDirectory()) {
        File[] fs = f.listFiles();
        if (fs == null || fs.length == 0)
            return;
        for (int i = 0; i < fs.length; i++)
            addFile(fs[i]);/*from w  ww  . java  2  s.  c o  m*/
        return;
    }

    if (f.isHidden())
        return;

    FileInfo info = new FileInfo(f);
    DicomObject dcmObj = new BasicDicomObject();
    DicomInputStream in = null;
    try {
        in = new DicomInputStream(f);
        in.setHandler(new StopTagInputHandler(Tag.StudyDate));
        in.readDicomObject(dcmObj, PEEK_LEN);
        info.tsuid = in.getTransferSyntax().uid();
        info.fmiEndPos = in.getEndOfFileMetaInfoPosition();
    } catch (IOException e) {
        e.printStackTrace();
        System.err.println("WARNING: Failed to parse " + f + " - skipped.");
        System.out.print('F');
        return;
    } finally {
        CloseUtils.safeClose(in);
    }
    info.cuid = dcmObj.getString(Tag.MediaStorageSOPClassUID, dcmObj.getString(Tag.SOPClassUID));
    if (info.cuid == null) {
        System.err.println("WARNING: Missing SOP Class UID in " + f + " - skipped.");
        System.out.print('F');
        return;
    }
    info.iuid = dcmObj.getString(Tag.MediaStorageSOPInstanceUID, dcmObj.getString(Tag.SOPInstanceUID));
    if (info.iuid == null) {
        System.err.println("WARNING: Missing SOP Instance UID in " + f + " - skipped.");
        System.out.print('F');
        return;
    }
    if (this.suffixUID != null)
        info.iuid = info.iuid + this.suffixUID[0];
    addTransferCapability(info.cuid, info.tsuid);
    this.files.add(info);
    System.out.print('.');
}

From source file:com.upload.DcmSnd.java

public void addFile(File f) {
    if (f.isDirectory()) {
        File[] fs = f.listFiles();
        if (fs == null || fs.length == 0)
            return;
        for (int i = 0; i < fs.length; i++)
            addFile(fs[i]);//from  ww  w  .j  a va  2 s. c o m
        return;
    }

    if (f.isHidden())
        return;

    FileInfo info = new FileInfo(f);
    DicomObject dcmObj = new BasicDicomObject();
    DicomInputStream in = null;
    try {
        in = new DicomInputStream(f);
        in.setHandler(new StopTagInputHandler(Tag.StudyDate));
        in.readDicomObject(dcmObj, PEEK_LEN);
        info.tsuid = in.getTransferSyntax().uid();
        info.fmiEndPos = in.getEndOfFileMetaInfoPosition();
    } catch (IOException e) {
        e.printStackTrace();
        System.err.println("WARNING: Failed to parse " + f + " - skipped.");
        System.out.print('F');
        return;
    } finally {
        CloseUtils.safeClose(in);
    }
    info.cuid = dcmObj.getString(Tag.MediaStorageSOPClassUID, dcmObj.getString(Tag.SOPClassUID));
    if (info.cuid == null) {
        System.err.println("WARNING: Missing SOP Class UID in " + f + " - skipped.");
        System.out.print('F');
        return;
    }
    //        info.iuid = dcmObj.getString(Tag.MediaStorageSOPInstanceUID,
    //                dcmObj.getString(Tag.SOPInstanceUID));
    info.iuid = dcmObj.getString(Tag.SOPInstanceUID, dcmObj.getString(Tag.SOPInstanceUID));
    if (info.iuid == null) {
        System.err.println("WARNING: Missing SOP Instance UID in " + f + " - skipped.");
        System.out.print('F');
        return;
    }
    if (suffixUID != null)
        info.iuid = info.iuid + suffixUID[0];
    addTransferCapability(info.cuid, info.tsuid);
    files.add(info);
    System.out.print('.');
}

From source file:org.pentaho.platform.repository.solution.filebased.FileBasedSolutionRepository.java

private void processSolutionTree(final Element parentNode, final File targetFile) {
    if (targetFile.isDirectory()) {
        if (!SolutionReposHelper.ignoreDirectory(targetFile.getName())) {
            Element childNode = parentNode.addElement(SolutionReposHelper.ENTRY_NODE_NAME)
                    .addAttribute(SolutionReposHelper.TYPE_ATTR_NAME, SolutionReposHelper.DIRECTORY_ATTR)
                    .addAttribute(SolutionReposHelper.NAME_ATTR_NAME, targetFile.getName());
            File files[] = targetFile.listFiles();
            for (File file : files) {
                processSolutionTree(childNode, file);
            }//from  ww w  .  j a  va2 s. c  om
        }
    } else {
        if (!targetFile.isHidden() && !SolutionReposHelper.ignoreFile(targetFile.getName())) {
            parentNode.addElement(SolutionReposHelper.ENTRY_NODE_NAME)
                    .addAttribute(SolutionReposHelper.TYPE_ATTR_NAME, SolutionReposHelper.FILE_ATTR)
                    .addAttribute(SolutionReposHelper.NAME_ATTR_NAME, targetFile.getName());
        }
    }
}