Advertisement
Guest User

Untitled

a guest
Jul 29th, 2016
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.11 KB | None | 0 0
  1. import java.io.*;
  2. import java.util.*;
  3.  
  4. public class Leerstellenvernichter extends Thread
  5. {
  6.  
  7. public static int mode = 0;
  8. public static boolean output = false;
  9. public static int scale = 100;
  10.  
  11. public static void main(String[] args)
  12. {
  13. (new Leerstellenvernichter(new File(args[0]))).start();
  14. if (args.length > 1 && args[1].equals("delete")) mode = 1;
  15. if (args.length > 2 && args[2].startsWith("scale=")) scale = Integer.valueOf(args[2].split("=")[1]);
  16. }
  17.  
  18. File root;
  19.  
  20. public Leerstellenvernichter(File path)
  21. {
  22. this.root = path;
  23. System.out.println(path.getAbsolutePath());
  24. }
  25.  
  26. public void out(String s)
  27. {
  28. if (output) System.out.println(s);
  29. }
  30.  
  31. @Override
  32. public void run()
  33. {
  34. try
  35. {
  36. if (root.listFiles().length == 0) root.delete();
  37. else
  38. {
  39. int i = 0;
  40. for(; i <= root.listFiles().length / scale; i++)
  41. {
  42. (new Checker(Arrays.copyOfRange(root.listFiles(), i * scale, (i + 1) * scale))).run();;
  43. }
  44.  
  45. if (root.listFiles().length == 0) root.delete();
  46. }
  47. } catch (Exception e)
  48. {
  49. e.printStackTrace();
  50. }
  51. }
  52.  
  53. class Checker extends Thread
  54. {
  55.  
  56. File[] array;
  57.  
  58. public Checker(File[] array)
  59. {
  60. this.array = array;
  61. }
  62.  
  63. @Override
  64. public void run()
  65. {
  66. for (File f : array)
  67. {
  68. if(f == null) continue;
  69. if (f.isDirectory()) (new Leerstellenvernichter(f)).run();
  70. else if (f.isFile())
  71. {
  72. boolean b = true;
  73. Scanner scan;
  74. try
  75. {
  76. scan = new Scanner(f);
  77.  
  78. while (scan.hasNext())
  79. if (!scan.nextLine().matches(" *"))
  80. {
  81. b = false;
  82. break;
  83. }
  84. scan.close();
  85. if (b)
  86. {
  87. if (Leerstellenvernichter.mode == 0)
  88. {
  89. String s = f.getAbsolutePath();
  90. s = s.substring(0, s.lastIndexOf("\\") + 1);
  91. s += "_" + f.getName();
  92. f.renameTo(new File(s));
  93. } else if (Leerstellenvernichter.mode == 1) if (f.delete()) System.out.println("deleted " + f.getAbsolutePath());
  94. }
  95. } catch (FileNotFoundException e)
  96. {
  97. e.printStackTrace();
  98. }
  99. }
  100. }
  101. }
  102.  
  103. }
  104.  
  105. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement