Delete files in a directory matching a filename filter
@param dir directory
@param filter filename filter, if null then delete all files
339504
public static void deleteFiles(File dir, FilenameFilter filter) {
        // validations
        if(dir == null) {
            throw new DataUtilException("The delete directory parameter can not be a null value");
        } else if(!dir.exists() || !dir.isDirectory()) {
            throw new DataUtilException("The delete directory does not exist: " + dir.getAbsolutePath());
        }

        // delete files
        File [] files;
        if(filter == null) {
            files = dir.listFiles();
        } else {
            files = dir.listFiles(filter);
        }
        if (files != null) {
            for(File file : files) {
                if(file.isFile()) {
                    if(!file.delete()) {
                        throw new DataUtilException("Failed to delete file: " + file.getAbsolutePath());
                    }
                }
            }
        }
    }
1264625
public static void deleteDirectory(Path dir) throws IOException {
		if(dir == null || !Files.exists(dir))
			return;
		Files.walkFileTree(dir, new SimpleFileVisitor<Path>() {
	        @Override
	        public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
	            Files.delete(file);
	            return FileVisitResult.CONTINUE;
	        }

	        @Override
	        public FileVisitResult postVisitDirectory(Path dir, IOException e) throws IOException {
	            if (e != null) {
	                throw e;
	            }
	            Files.delete(dir);
	            return FileVisitResult.CONTINUE;
	        }
	    });
	}
272077
def _remove_files(self, directory, pattern):
        '''
        
        '''
        for root, dirnames, file_names in os.walk(directory):
            for file_name in fnmatch.filter(file_names, pattern):
                os.remove(os.path.join(root, file_name))
597942
private static void init(List<File> list, File dir, Filter filter)
    {
        File[] files = dir.listFiles();
        for (int i = 0; i < files.length; i++)
        {
            if (files[i].isDirectory())
            {
                init(list, files[i], filter);
            }
            else
            {
                if (filter == null || filter.accepts(files[i].getAbsolutePath()))
                {
                    list.add(files[i]);
                }
            }
        }
    }
225566
public static boolean deleteFile(final File file) {
		// delete directory content recursively
		if (file.isDirectory()) {
			final File[] children = file.listFiles();
			for (File child : children) {
				if (!deleteFile(child)) {
					return false;
				}
			}
		}

		// delete file/empty directory
		return file.delete();
	}
663798
public static void recursivelyDeleteDirectoryOnExit(final File directory) {
    Runtime.getRuntime().addShutdownHook(new Thread() {
      @Override
      public void run() {
        try {
          recursivelyDeleteDirectory(directory);
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }
    });
  }
1002938
public static List<File> listFiles(File[] directories, IOFileFilter fileFilter, IOFileFilter dirFilter) {
        List<File> files = new ArrayList<>();
        for (File directory : directories) {
            if (!directory.isDirectory()) {
                continue;
            }
            Collection<File> filesInDirectory = FileUtils.listFiles(directory,
                    fileFilter,
                    dirFilter);
            files.addAll(filesInDirectory);
        }
        return files;
    }
1276093
public static void deleteChilsDirsIfEmpty(File dir){
		File childs[]=getChildDirs(dir);
		
		for (File file:childs){
			deleteChilsDirsIfEmpty(file);
			if (!file.delete()) {
				log.info("No se ha podido borrar el directorio " + file.getAbsolutePath());
			}
		}
		
	}
769476
private synchronized static void delete(File file) {
        // Check if file is directory
        if (file.isDirectory()) {
            // Get all files in the folder
            File[] files = file.listFiles();

            // Delete each file in the folder
            for (int i = 0; i < files.length; ++i) {
                delete(files[i]);
            }

            // Delete the folder
            file.delete();
        } else {
            // Delete the file if it is not a folder
            file.delete();
        }
    }
871538
def clean_out_dir(directory):
    
    if not isinstance(directory, path):
        directory = path(directory)
    for file_path in directory.files():
        file_path.remove()
    for dir_path in directory.dirs():
        dir_path.rmtree()
264769
public static void purgeDirectory(File directory) {

        if (directory.canRead() && directory.isDirectory()) {
            File[] files = directory.listFiles();
            for (int i = 0; i < files.length; i++) {
                File f = files[i];
                if (f.isDirectory()) {
                    purgeDirectory(f);
                }
                if (f.canWrite()) {
                    f.delete();
                }
            }
            directory.delete();
        }
    }
163884
public static void deleteDirectory(File dir) {
        if (!dir.exists()) {
            return;
        }

        if (dir.isDirectory()) {
            for (File child : dir.listFiles()) {
                deleteDirectory(child);
            }
            dir.delete();
        } else {
            dir.delete();
        }
    }
838830
public static void deleteDirectory(File directory) throws IOException {
    requireNonNull(directory, DIRECTORY_CAN_NOT_BE_NULL);
    deleteDirectoryImpl(directory.toPath());
  }
655793
public static void delete(FileSystem fs, String name) throws IOException {
    Path dir = new Path(name);
    Path data = new Path(dir, DATA_FILE_NAME);
    Path index = new Path(dir, INDEX_FILE_NAME);

    fs.delete(data, true);
    fs.delete(index, true);
    fs.delete(dir, true);
  }
1032
public static function deleteAllFilesInDirectory ($dir) {
        $dirIterator = new \RecursiveDirectoryIterator($dir, \FilesystemIterator::SKIP_DOTS);
        foreach (new \RecursiveIteratorIterator($dirIterator, \RecursiveIteratorIterator::CHILD_FIRST) as $file) {
            $file->isDir() ? rmdir($file) : unlink($file);
        }
    }
261436
public static List<File> listFiles(File dir, FileFilter filter, boolean recursive){
		List<File> list = new ArrayList<File>();
		listFilesInternal(list, dir, filter, recursive);
		return list;
	}
164937
public static boolean deleteDirContents(final File dir) {
        if (dir.isDirectory()) {
            final String[] children = dir.list();
            for (final String aChildren : children) {
                final File child = new File(dir, aChildren);
                if (child.isDirectory()) {
                    // Delete the sub directories
                    if (!deleteDir(child)) {
                        return false;
                    }
                } else {
                    // Delete a single file in the directory
                    if (!child.delete()) {
                        return false;
                    }
                }
            }
        }
        return true;
    }