Java Developer

ot-clean, Wildcards

Since version 0.4 ot-clean is able to search for and remove specific files using wildcards. Thanks to DirectoryScanner I was able to implement wildcard support. I am using this feature to unclutter directories from log files. When I execute ot-clean with following YAML:

deletes:
 - "**/*.log"

It is looking for all log files

[INFO] 19:23:48 clean.Delete: Directory 'D:\work\.postgres\pg_log\postgresql-2016-02-24_104409.log' can be deleted.
[INFO] 19:23:48 clean.Delete: Directory 'D:\work\.postgres\pg_log\postgresql-2016-02-25_000000.log' can be deleted.
[INFO] 19:23:48 clean.Delete: Directory 'D:\work\.postgres\pg_log\postgresql-2016-02-26_000000.log' can be deleted.
[INFO] 19:23:48 clean.Delete: Directory 'D:\work\contend\test.log' can be deleted.

Usage of directory scanner

Thanks to DirectoryScanner I was able to convert list of input wildcard paths into the stream of files or directories that should have been deleted.

public Stream<Path> filesToDelete(final Path path) {
    final DirectoryScanner scanner = new DirectoryScanner();
    scanner.setIncludes(this.deletes.toArray(new String[this.deletes.size()]));
    scanner.setBasedir(path.toFile());
    scanner.setCaseSensitive(false);
    scanner.scan();
    return Stream.concat(
        Arrays.stream(scanner.getIncludedDirectories()),
        Arrays.stream(scanner.getIncludedFiles())
    ).map(path::resolve);
}

The ot-clean series

This blog post is one of the series about the ot-clean. Simple open source tool that maintains your projects directories cleaned from all the garbage. Feel free to look at the source code or readme page for more information. You can also submit pull request or post suggestion. This text participates in open source blogging competition.

Project status

Build Status

All posts from the ot-clean series


Like it? Share it on , , ,

About the author

Grzegorz Gajos, Software Architect with international consulting and programming background. Co-founder of Open Tangerine Software House. Quality evangelist. An experienced entrepreneur, out of the box thinker and problem solver.