Example usage for java.io FileFilter FileFilter

List of usage examples for java.io FileFilter FileFilter

Introduction

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

Prototype

FileFilter

Source Link

Usage

From source file:com.microsoft.tfs.core.clients.versioncontrol.internal.localworkspace.LocalWorkspaceProperties.java

public void applyAceToBaselineFolders(final String sidString, final boolean addOrRemove) {
    // Check.notNullOrEmpty(sidString, "sidString"); //$NON-NLS-1$

    BaselineFolder.ensureLocalMetadataDirectoryExists(workspace);

    final List<File> foldersToReceiveAce = new ArrayList<File>(baselineFolders.size() + 1);
    foldersToReceiveAce.add(new File(workspace.getLocalMetadataDirectory()));

    for (final BaselineFolder baselineFolder : baselineFolders) {
        foldersToReceiveAce.add(new File(baselineFolder.getPath()));
    }/*  ww  w.j  a  va  2  s. c  om*/

    for (int i = 0; i < foldersToReceiveAce.size(); i++) {
        final File folderToReceiveAce = foldersToReceiveAce.get(i);
        applyAceToFileOrFolder(folderToReceiveAce.getAbsolutePath(), sidString, addOrRemove);

        if (!Platform.isCurrentPlatform(Platform.WINDOWS)) {
            final File[] subFolders = folderToReceiveAce.listFiles(new FileFilter() {
                @Override
                public boolean accept(final File file) {
                    if (file.isDirectory()) {
                        return true;
                    } else {
                        applyAceToFileOrFolder(file.getAbsolutePath(), sidString, addOrRemove);
                        return false;
                    }
                }
            });

            foldersToReceiveAce.addAll(Arrays.asList(subFolders));
        }
    }
}

From source file:fr.msch.wissl.server.REST.java

@GET
@Path("folders/listing")
public String getFolderListing(@QueryParam("directory") String directory) throws SecurityError, SQLException {
    long l1 = System.nanoTime();
    String sid = (sessionIdHeader == null ? sessionIdGet : sessionIdHeader);
    Session sess = Session.check(sid, request.getRemoteAddr(), userAgent, true);
    StringBuilder ret = new StringBuilder();

    File dir = null;//from   w w w . j av  a  2  s  .  c  o  m
    File[] l = null;
    String dirName = null;

    if (directory == null || directory.trim().length() == 0) {
        dir = new File(System.getProperty("user.home"));
        l = dir.listFiles(new FileFilter() {
            @Override
            public boolean accept(File pathname) {
                return pathname.isDirectory();
            }
        });
        dirName = dir.getAbsolutePath();
    } else if (directory.equals("$ROOT")) {
        dirName = "";
        l = File.listRoots();
    } else {
        dir = new File(directory);

        if (!dir.exists()) {
            throw new NotFoundException("Unknown directory: " + directory);
        } else if (!dir.isDirectory()) {
            throw new IllegalArgumentException("Not a directory: " + directory);
        }

        l = dir.listFiles(new FileFilter() {
            @Override
            public boolean accept(File pathname) {
                return pathname.isDirectory();
            }
        });
        dirName = dir.getAbsolutePath();
    }

    ret.append("{\"directory\":" + JSONObject.quote(dirName));
    ret.append(",\"separator\":" + JSONObject.quote(File.separator));
    if (dir != null && dir.getParent() != null) {
        ret.append(",\"parent\":" + JSONObject.quote(dir.getParent()));
    } else {
        ret.append(",\"parent\":" + JSONObject.quote("$ROOT"));
    }
    ret.append(",\"listing\":[");
    if (l != null) {
        Arrays.sort(l);
        boolean virgule = false;
        for (int i = 0; i < l.length; i++) {
            if (l[i].exists()) {
                if (virgule) {
                    ret.append(',');
                }
                virgule = (i + 1 < l.length);
                ret.append(JSONObject.quote(l[i].getAbsolutePath()));
            }
        }
    }
    ret.append("]}");

    nocache();
    log(sess, l1);
    return ret.toString();
}

From source file:com.ichi2.libanki.Utils.java

/** Returns a list of apkg-files. */
public static List<File> getImportableDecks(Context context) {
    String deckPath = CollectionHelper.getCurrentAnkiDroidDirectory(context);
    File dir = new File(deckPath);
    int deckCount = 0;
    File[] deckList = null;//from w w w . ja  va 2 s . c  om
    if (dir.exists() && dir.isDirectory()) {
        deckList = dir.listFiles(new FileFilter() {
            @Override
            public boolean accept(File pathname) {
                return pathname.isFile() && pathname.getName().endsWith(".apkg");
            }
        });
        deckCount = deckList.length;
    }
    List<File> decks = new ArrayList<File>();
    decks.addAll(Arrays.asList(deckList).subList(0, deckCount));
    return decks;
}

From source file:com.actuate.development.tool.task.InstallBRDPro.java

private void cleanInstallFile(IProgressMonitor monitor) throws IOException {
    FileUtil.deleteFile(monitor, new File(data.getDirectory(), "bodtools"));
    FileUtil.deleteFile(monitor, new File(data.getDirectory(), "oda"));
    FileUtil.deleteFile(monitor, new File(data.getDirectory(), "resources"));
    FileUtil.deleteFile(monitor, new File(data.getDirectory(), "MyClasses"));
    FileUtil.deleteFile(monitor, new File(data.getDirectory(), "License"));
    FileUtil.deleteFile(monitor, new File(data.getDirectory(), "setup"));
    FileUtil.deleteFile(monitor, new File(data.getDirectory(), "ico"));
    FileUtil.deleteFile(monitor, new File(data.getDirectory(), "3rdparty_products.txt"));
    FileUtil.deleteFile(monitor, new File(data.getDirectory(), "startbrdpro.bat"));
    FileUtil.deleteFile(monitor, new File(data.getDirectory(), "eclipse\\p2"));
    FileUtil.deleteFile(monitor, new File(data.getDirectory(), "startbrdpro.bat"));
    FileUtil.deleteFile(monitor, new File(data.getDirectory(), "eclipse\\eclipse.lnk"));

    File configs = new File(data.getDirectory(), "eclipse\\configuration");
    File[] files = configs.listFiles();
    if (files != null) {
        for (int i = 0; i < files.length; i++) {
            if (monitor.isCanceled()) {
                return;
            }/*from   ww w  .j av  a 2  s .c  o  m*/
            if (files[i].getName().equalsIgnoreCase(".settings"))
                continue;
            FileUtil.deleteFile(monitor, files[i]);
        }
    }

    File uninstallFile = new File(data.getDirectory(), "uninstall.data");
    boolean startBRDPro = false;
    boolean startSource = false;
    boolean startLink = false;
    if (uninstallFile.exists()) {
        BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(uninstallFile)));
        String line;
        while ((line = in.readLine()) != null) {
            if (monitor.isCanceled()) {
                in.close();
                return;
            }

            line = line.trim();
            if (line.length() == 0)
                continue;
            if (line.equalsIgnoreCase("[BRDPro]")) {
                startBRDPro = true;
                startSource = false;
                startLink = false;
            } else if (line.equalsIgnoreCase("[Source]")) {
                startBRDPro = false;
                startSource = true;
                startLink = false;
            } else if (line.equalsIgnoreCase("[Link]")) {
                startBRDPro = false;
                startSource = false;
                startLink = true;
            } else {
                if (startBRDPro) {
                    File file = new File(data.getDirectory(), line);
                    if (file.exists()) {
                        if (file.isFile()) {
                            if (line.indexOf("configuration\\.settings") != -1)
                                continue;
                            file.delete();
                        } else {
                            deleteDirectory(file);
                        }
                    }
                } else if (startSource) {
                    File file = new File(data.getDirectory(), line);
                    if (file.exists()) {
                        if (file.isFile())
                            file.delete();
                    }
                } else if (startLink) {
                    FileUtil.deleteFile(monitor,
                            new File(data.getDirectory(), "eclipse\\links\\" + line + ".link"));
                    FileUtil.deleteFile(monitor, new File(data.getDirectory(), "links\\" + line));
                }
            }

        }
        in.close();
    }

    if (!monitor.isCanceled()) {
        deleteDirectory(new File(data.getDirectory(), "eclipse\\links"));
        deleteDirectory(new File(data.getDirectory(), "links"));
    } else
        return;

    File[] tempDirs = new File(data.getDirectory()).listFiles(new FileFilter() {

        public boolean accept(File file) {
            if (file.getName().startsWith("temp")
                    && file.getName().length() == new File(data.getTempDir()).getName().length()
                    && file.isDirectory()) {
                return true;
            }
            return false;
        }

    });

    if (tempDirs != null) {
        for (int i = 0; i < tempDirs.length; i++) {
            if (monitor.isCanceled())
                return;
            FileUtil.deleteDirectory(monitor, tempDirs[i]);
        }
    }
    // FileUtil.deleteFile( uninstallFile );
}

From source file:io.personium.core.model.impl.fs.DavCmpFsImpl.java

private File[] getChildDir() {
    File[] children = this.fsDir.listFiles(new FileFilter() {
        @Override/*from  w w  w  .  jav a 2s. c o m*/
        public boolean accept(File child) {
            if (child.isDirectory()) {
                return true;
            }
            return false;
        }

    });
    return children;
}

From source file:net.sf.zekr.common.config.ApplicationConfig.java

@SuppressWarnings("unchecked")
private void extractAudioProps() {
    String def = props.getString("audio.default");
    List<String> selectedList = props.getList("audio.default");
    if (org.apache.commons.collections.CollectionUtils.isNotEmpty(selectedList) && selectedList.size() > 1) {
        def = selectedList.get(0);/*  w w  w. j a v a2  s .c o m*/
    }
    logger.info("Loading audio .properties files.");

    String[] paths = { ApplicationPath.AUDIO_DIR, Naming.getAudioDir() };
    for (int pathIndex = 0; pathIndex < paths.length; pathIndex++) {
        File audioDir = new File(paths[pathIndex]);
        if (!audioDir.exists()) {
            continue;
        }

        logger.info("Loading audio files info from: " + audioDir);
        FileFilter filter = new FileFilter() { // accept .properties files
            public boolean accept(File pathname) {
                if (pathname.getName().toLowerCase().endsWith(".properties")) {
                    return true;
                }
                return false;
            }
        };
        File[] audioPropFiles = audioDir.listFiles(filter);

        for (int audioIndex = 0; audioIndex < audioPropFiles.length; audioIndex++) {
            try {
                AudioData audioData = loadAudioData(audioPropFiles[audioIndex], true);
                if (audioData == null || audioData.getId() == null) {
                    continue;
                }

                audio.add(audioData);
                if (audioData.id.equals(def)) {
                    logger.info("Default recitation is: " + audioData);
                    audio.setCurrent(audioData);
                }
            } catch (Exception e) {
                logger.warn("Can not load audio pack \"" + audioPropFiles[audioIndex]
                        + "\" properly because of the following exception:");
                logger.log(e);
            }
        }
    }

    if (audio.getCurrent() == null) {
        logger.error("No default recitation found: " + def);
        if (audio.getAllAudio().size() > 0) {
            for (AudioData ad : audio.getAllAudio()) {
                if ("offline".equals(ad.type)) {
                    audio.setCurrent(ad);
                    props.setProperty("audio.default", ad.id);
                    logger.warn("Setting another recitation as default: " + audio.getCurrent());
                    break;
                }
            }
            if (audio.getCurrent() == null) {
                audio.setCurrent(audio.getAllAudio().iterator().next());
                props.setProperty("audio.default", audio.getCurrent().id);
                logger.warn("Setting another recitation as default: " + audio.getCurrent());
            }
        } else {
            logger.warn("No other recitation found. Audio will be disabled.");
        }
    }

    // load if list of default audio data
    if (audio.getCurrent() != null) {
        // audio.getCurrentList().add(audio.getCurrent());
        for (String audioId : selectedList) {
            AudioData ad = audio.get(audioId);
            if (ad != null) {
                audio.getCurrentList().add(ad);
            }
        }
        if (audio.getCurrentList().size() <= 0) {
            audio.getCurrentList().add(audio.getCurrent());
        }
    }
}

From source file:com.hichinaschool.flashcards.libanki.Utils.java

/** Returns a list of apkg-files. */
public static List<File> getImportableDecks() {
    String deckPath = AnkiDroidApp.getCurrentAnkiDroidDirectory();
    File dir = new File(deckPath);
    int deckCount = 0;
    File[] deckList = null;/*w  ww  .  j  a  va2 s .c o m*/
    if (dir.exists() && dir.isDirectory()) {
        deckList = dir.listFiles(new FileFilter() {
            @Override
            public boolean accept(File pathname) {
                if (pathname.isFile() && pathname.getName().endsWith(".apkg")) {
                    return true;
                }
                return false;
            }
        });
        deckCount = deckList.length;
    }
    List<File> decks = new ArrayList<File>();
    for (int i = 0; i < deckCount; i++) {
        decks.add(deckList[i]);
    }
    return decks;
}

From source file:gtu._work.etc._3DSMovieRenamer.java

void loadDirVids() {
    if (!loadDir.isDirectory()) {
        return;//from ww w  . j a  va  2s  .co  m
    }
    DefaultListModel vidListModel = new DefaultListModel();
    for (File f : loadDir.listFiles(new FileFilter() {
        public boolean accept(File pathname) {
            if (pathname.getName().toLowerCase().endsWith(".avi")) {
                return true;
            }
            return false;
        }
    })) {
        vidListModel.addElement(f);
    }
    if (vidListModel.size() == 0) {
        JOptionPaneUtil.newInstance().iconErrorMessage().showMessageDialog("no avi file", getTitle());
    }
    vidList.setModel(vidListModel);
}

From source file:com.amalto.core.util.Util.java

public static WSMDMJob[] getMDMJobs() {
    // Retrieve jobs from jobox only (zip deployment)
    // TODO: Still support war deployements??
    List<WSMDMJob> jobs = new ArrayList<>();
    try {//from  ww w . j  a  v a2s .co m
        FileFilter filter = new FileFilter() {

            @Override
            public boolean accept(File pathName) {
                return pathName.isDirectory()
                        || (pathName.isFile() && pathName.getName().toLowerCase().endsWith(".zip")); //$NON-NLS-1$
            }
        };
        List<File> zipFiles = listFiles(filter, new File(JobContainer.getUniqueInstance().getDeployDir()));

        for (File zip : zipFiles) {
            WSMDMJob job = getJobInfo(zip.getAbsolutePath());
            if (job != null) {
                jobs.add(job);
            }
        }
    } catch (Exception e) {
        LOGGER.error(e.getMessage(), e);
    }
    return jobs.toArray(new WSMDMJob[jobs.size()]);
}

From source file:com.door43.translationstudio.core.TargetTranslation.java

/**
 * Returns the number of items that have been translated
 * @return// www . j  ava  2s  .  co  m
 */
public int numTranslated() {
    int numFiles = 0;
    File[] chapterDirs = targetTranslationDir.listFiles(new FileFilter() {
        @Override
        public boolean accept(File pathname) {
            return pathname.isDirectory() && !pathname.getName().equals(".git")
                    && !pathname.getName().equals("manifest.json");
        }
    });
    if (chapterDirs != null) {
        for (File dir : chapterDirs) {
            String[] files = dir.list();
            if (files != null) {
                numFiles += files.length;
            }
        }
    }
    return numFiles;
}