Example usage for org.apache.commons.io FileDeleteStrategy deleteQuietly

List of usage examples for org.apache.commons.io FileDeleteStrategy deleteQuietly

Introduction

In this page you can find the example usage for org.apache.commons.io FileDeleteStrategy deleteQuietly.

Prototype

public boolean deleteQuietly(File fileToDelete) 

Source Link

Document

Deletes the file object, which may be a file or a directory.

Usage

From source file:fr.duminy.jbackup.core.util.DefaultFileDeleter.java

private void deleteFiles(FileDeleteStrategy deleteStrategy, List<Path> paths, boolean expectFiles) {
    if (paths != null) {
        for (Path path : paths) {
            boolean deleted = false;

            try {
                PathUtils.setReadable(path, true);

                if (expectFiles && Files.isRegularFile(path)) {
                    deleted = deleteStrategy.deleteQuietly(path.toFile());
                } else if (!expectFiles && Files.isDirectory(path)) {
                    deleted = deleteStrategy.deleteQuietly(path.toFile());
                } else {
                    LOG.error("Wrong path type. Expected: {} Actual: {} {}",
                            new Object[] { (expectFiles ? "file" : "directory"),
                                    (Files.isRegularFile(path) ? "file" : ""),
                                    (Files.isDirectory(path) ? "directory" : "") });
                    deleted = false;//from   w  w  w.j  a va  2  s  . co  m
                }
            } catch (IOException e) {
                deleted = false;
            }

            if (deleted) {
                LOG.info("{} : deleted", path);
            } else {
                LOG.error("{} : NOT DELETED", path);
            }
        }
    }
}