Skip to content

Latest commit

 

History

History
97 lines (73 loc) · 2.92 KB

File metadata and controls

97 lines (73 loc) · 2.92 KB

License Coverage Status GitHub Workflow Status (branch)

java-filesearch

Java filesearch reimagined.

Maven

Add the Jitpack repository to your build file

<repositories>
    <repository>
        <id>jitpack.io</id>
        <url>https://jitpack.io</url>
    </repository>
</repositories>

Release artifact

<dependency>
    <groupId>com.github.zrdj</groupId>
    <artifactId>java-filesearch</artifactId>
    <version>0.4.1</version>
</dependency>

Motivation

This is just a fun project to reimplement the horrible file walking implementation from the JDK, trying to combine the two Java APIs of File.listFiles() and Files.walkFileTree() into a new API using Java's new Stream<T> feature of version 8.

To search for files simply start with the static method Search.search() and search for executable (.exe) files ...

... not recursively using the Path API

    import static com.github.zrdj.java.filesearch.Search.search;

public void doSomeFileSearchStuff() {
    final List<Path> executables = search().directory("S:\Earch\Path").notRecursively().byPath()
            .stream()
            .filter(p -> p.getFileName().toString().endsWith(".exe"))
            .collect(Collectors.toList());
    // do something with found files
}

... or recursively using the Path API

    import static com.github.zrdj.java.filesearch.Search.search;

public void doSomeFileSearchStuff() {
    final List<Path> executables = search().directory("S:\Earch\Path").recursively().byPath()
            .stream()
            .filter(p -> p.getFileName().toString().endsWith(".exe"))
            .collect(Collectors.toList());
    // do something with found files
}

... or not recursively using the File API

    import static com.github.zrdj.java.filesearch.Search.search;

public void doSomeFileSearchStuff() {
    final List<File> executables = search().directory("S:\Earch\Path").notRecursively().byFile()
            .stream()
            .filter(f -> f.getName().endsWith(".exe"))
            .collect(Collectors.toList());
    // do something with found files
}

... or recursively using the File API

    import static com.github.zrdj.java.filesearch.Search.search;

public void doSomeFileSearchStuff() {
    final List<File> executables = search().directory("S:\Earch\Path").recursively().byFile()
            .stream()
            .filter(f -> f.getName().endsWith(".exe"))
            .collect(Collectors.toList());
    // do something with found files
}