Skip to content

Instantly share code, notes, and snippets.

@kishaningithub
Last active August 29, 2015 14:26
Show Gist options
  • Save kishaningithub/203ef354858e9e765bda to your computer and use it in GitHub Desktop.
Save kishaningithub/203ef354858e9e765bda to your computer and use it in GitHub Desktop.

Revisions

  1. kishaningithub revised this gist Aug 1, 2015. 1 changed file with 13 additions and 2 deletions.
    15 changes: 13 additions & 2 deletions BakFileDestroyer.java
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,5 @@
    package com.kishan;

    import java.io.IOException;
    import java.nio.file.Files;
    import java.nio.file.Path;
    @@ -12,7 +14,16 @@ public static void main(String[] args) throws IOException
    try(Scanner sc = new Scanner(System.in)){
    System.out.println("Enter path:");
    Path rootPath = Paths.get(sc.nextLine().trim());
    Files.find(rootPath, Integer.MAX_VALUE, (path, basicFileAttrs) -> path.toString().toLowerCase().endsWith(".bak")).forEach(System.out::println);
    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();
    }
    });
    }
    }
    }
    }
  2. kishaningithub created this gist Aug 1, 2015.
    18 changes: 18 additions & 0 deletions BakFileDestroyer.java
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    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());
    Files.find(rootPath, Integer.MAX_VALUE, (path, basicFileAttrs) -> path.toString().toLowerCase().endsWith(".bak")).forEach(System.out::println);
    }
    }
    }