Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.util.*;
- public class Leerstellenvernichter extends Thread
- {
- public static int mode = 0;
- public static boolean output = false;
- public static int scale = 100;
- public static void main(String[] args)
- {
- (new Leerstellenvernichter(new File(args[0]))).start();
- if (args.length > 1 && args[1].equals("delete")) mode = 1;
- if (args.length > 2 && args[2].startsWith("scale=")) scale = Integer.valueOf(args[2].split("=")[1]);
- }
- File root;
- public Leerstellenvernichter(File path)
- {
- this.root = path;
- System.out.println(path.getAbsolutePath());
- }
- public void out(String s)
- {
- if (output) System.out.println(s);
- }
- @Override
- public void run()
- {
- try
- {
- if (root.listFiles().length == 0) root.delete();
- else
- {
- int i = 0;
- for(; i <= root.listFiles().length / scale; i++)
- {
- (new Checker(Arrays.copyOfRange(root.listFiles(), i * scale, (i + 1) * scale))).run();;
- }
- if (root.listFiles().length == 0) root.delete();
- }
- } catch (Exception e)
- {
- e.printStackTrace();
- }
- }
- class Checker extends Thread
- {
- File[] array;
- public Checker(File[] array)
- {
- this.array = array;
- }
- @Override
- public void run()
- {
- for (File f : array)
- {
- if(f == null) continue;
- if (f.isDirectory()) (new Leerstellenvernichter(f)).run();
- else if (f.isFile())
- {
- boolean b = true;
- Scanner scan;
- try
- {
- scan = new Scanner(f);
- while (scan.hasNext())
- if (!scan.nextLine().matches(" *"))
- {
- b = false;
- break;
- }
- scan.close();
- if (b)
- {
- if (Leerstellenvernichter.mode == 0)
- {
- String s = f.getAbsolutePath();
- s = s.substring(0, s.lastIndexOf("\\") + 1);
- s += "_" + f.getName();
- f.renameTo(new File(s));
- } else if (Leerstellenvernichter.mode == 1) if (f.delete()) System.out.println("deleted " + f.getAbsolutePath());
- }
- } catch (FileNotFoundException e)
- {
- e.printStackTrace();
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement