Here you can find the source of deleteFilesinPath(File pBaseDir, String pFileName)
public static Boolean deleteFilesinPath(File pBaseDir, String pFileName) throws Exception
//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; } }