Java File Path Delete deleteFilesinPath(File pBaseDir, String pFileName)

Here you can find the source of deleteFilesinPath(File pBaseDir, String pFileName)

Description

delete Filesin Path

License

Open Source License

Declaration

public static Boolean deleteFilesinPath(File pBaseDir, String pFileName) throws Exception 

Method Source Code

//package com.java2s;
/**/*from  w  w w .  ja  v a  2  s . c o  m*/
 * Copyright (C) 2008-2010, Squale Project - http://www.squale.org
 *
 * This file is part of Squale.
 *
 * Squale is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or any later version.
 *
 * Squale is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with Squale.  If not, see <http://www.gnu.org/licenses/>.
 */

import java.io.File;

import java.util.ArrayList;

import java.util.Collection;

import java.util.Iterator;

public class Main {

    public static Boolean deleteFilesinPath(File pBaseDir, String pFileName) throws Exception {
        Collection listFilesToRemove = findFiles(pBaseDir, pFileName);
        Integer objectif = listFilesToRemove.size();
        Integer resultat = 0;
        Iterator it = listFilesToRemove.iterator();
        while (it.hasNext()) {
            File current = (File) it.next();
            Boolean result = current.delete();
            if (result.booleanValue()) {
                resultat++;
            }
        }
        Boolean out = false;
        if (objectif.equals(resultat)) {
            out = true;
        }
        return out;
    }

    public static Collection findFiles(File pDirectory, String pFileName) {
        Collection result = new ArrayList();
        File[] files = pDirectory.listFiles();
        if (files != null) {
            for (int i = 0; i < files.length; i++) {
                File file = files[i];
                if (file.isDirectory()) {
                    result.addAll(findFiles(file, pFileName));
                } else if (file.getName().equalsIgnoreCase(pFileName)) {
                    result.add(file);
                }
            }
        }
        return result;
    }
}

Related

  1. deleteFiles(final File pathname)
  2. deleteFiles(String actionPath, String filePath)
  3. deleteFiles(String filePath)
  4. deleteFilesInDirectory(File path)
  5. deleteFilesInDirectory(String pathname)
  6. deleteFilesRecursive(final File path)
  7. deleteFileSystemDirectory(String dirPath)
  8. deleteFileSystemDirectory(String dirPath)
  9. deleteFileWithoutException(final String path)