Skip to content

Instantly share code, notes, and snippets.

@kishaningithub
Last active August 29, 2015 14:26
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kishaningithub/203ef354858e9e765bda to your computer and use it in GitHub Desktop.
Save kishaningithub/203ef354858e9e765bda to your computer and use it in GitHub Desktop.
Java 8 Code Utils
package com.kishan;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Scanner;
public class BakFileDestroyer
{
public static void main(String[] args) throws IOException
{
System.out.println("BAK File Destroyer");
try(Scanner sc = new Scanner(System.in)){
System.out.println("Enter path:");
Path rootPath = Paths.get(sc.nextLine().trim());
System.out.println("Enter extension (.bak):");
String fileExtension = sc.nextLine().trim();
Files.find(rootPath, Integer.MAX_VALUE, (path, basicFileAttrs) -> path.toString().toLowerCase().endsWith(fileExtension.isEmpty() ? ".bak" : fileExtension)).forEach(path -> {
try {
Files.delete(path);
System.out.println("Deleted: " + path.toString());
} catch (Exception e) {
e.printStackTrace();
}
});
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment