Last active
August 29, 2015 14:26
-
-
Save kishaningithub/203ef354858e9e765bda to your computer and use it in GitHub Desktop.
Java 8 Code Utils
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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