Advertisement
Guest User

Untitled

a guest
Jun 24th, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.57 KB | None | 0 0
  1. // variables //
  2. string path = @"D:GamesNew folderSongs"; // change to your songs folder
  3. List<string> thingsToDel = new List<string>();
  4.  
  5.  
  6.  
  7. // delete duplicate directories //
  8. string[] allDirs = Directory.GetDirectories(path);
  9. // the amount of characters (counting from the beginning of the dir name) that have to match before it's counted as a duplicate
  10. int indexesToCheck = 8;
  11.  
  12. for (int i = 0; i < allDirs.Length; i++)
  13. {
  14. // makes a substring with 'indexesToCheck' amount of characters from the directory name
  15. string dirStart = allDirs[i].Substring(path.Length + 2, indexesToCheck);
  16. // the +2 is because the path allDirs[i] has an additional '//'
  17.  
  18. // goes trough every dir above i and compares it to 'dirStart'
  19. for (int j = i + 1; j < allDirs.Length; j++)
  20. {
  21. // makes another substring
  22. string otherDirStart = allDirs[j].Substring(path.Length + 2, indexesToCheck);
  23. // if they match, the dir of index i will be deleted later on
  24. if (dirStart == otherDirStart)
  25. {
  26. thingsToDel.Add(allDirs[i]);
  27. break;
  28. }
  29. }
  30. }
  31.  
  32. // deletes everything in 'thingsToDel'
  33. foreach (string thing in thingsToDel)
  34. {
  35. Directory.Delete(thing, true);
  36. // the true stands for deleting directories, even if they have subdirectories/files
  37. }
  38. thingsToDel.Clear();
  39.  
  40.  
  41.  
  42. // delete files that do not match my needs //
  43. string[] allFiles = Directory.GetFiles(path, "*.osu", SearchOption.AllDirectories);
  44. // .osu files are comparable to .ini files
  45.  
  46. // if true, the file will not be deleted
  47. bool fileIsCorrect = false;
  48. // if true, the file has mania as mode and needs an aditional check
  49. bool modeIsMania = false;
  50.  
  51. // checks for each file, if it should be deleted
  52. foreach (string file in allFiles)
  53. {
  54. fileIsCorrect = false;
  55. modeIsMania = false;
  56. string[] lines = File.ReadAllLines(file);
  57.  
  58. foreach (string line in lines)
  59. {
  60. // format is: Mode = (number between 0 and 3)
  61. if (line.Contains("Mode"))
  62. {
  63. if (line.Contains("0")) // change to your gamemode/s (add || line.Contains("x") to add one)
  64. {
  65. fileIsCorrect = true;
  66. }
  67. else if (line.Contains("3")) // delete these 4 rows if you don't want mania maps
  68. {
  69. modeIsMania = true;
  70. }
  71. }
  72. else if (modeIsMania && (line.Contains("CircleSize") && (line.Contains("4") || line.Contains("7") || line.Contains("10"))))
  73. { // circlesize is an additional check that only mode mania/3 needs
  74. fileIsCorrect = true;
  75. }
  76. }
  77.  
  78. if (!fileIsCorrect)
  79. {
  80. thingsToDel.Add(file);
  81. }
  82. }
  83.  
  84. foreach (string thing in thingsToDel)
  85. {
  86. File.Delete(thing);
  87. }
  88. thingsToDel.Clear();
  89.  
  90.  
  91.  
  92. // delete directories without .osu files //
  93. allDirs = Directory.GetDirectories(path);
  94.  
  95. foreach (string dir in allDirs)
  96. {
  97. // if a dir does not have at least 1 .osu file in it, it will be delete later
  98. if (Directory.GetFiles(dir, "*.osu").Length == 0)
  99. {
  100. thingsToDel.Add(dir);
  101. }
  102. }
  103.  
  104. foreach (string thing in thingsToDel)
  105. {
  106. Directory.Delete(thing, true);
  107. }
  108. thingsToDel.Clear();
  109.  
  110.  
  111.  
  112. // end of program //
  113. Console.WriteLine(
  114. "The Program is finished!n" +
  115. "Press any key to exit...");
  116. Console.ReadKey();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement