Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // variables //
- string path = @"D:GamesNew folderSongs"; // change to your songs folder
- List<string> thingsToDel = new List<string>();
- // delete duplicate directories //
- string[] allDirs = Directory.GetDirectories(path);
- // the amount of characters (counting from the beginning of the dir name) that have to match before it's counted as a duplicate
- int indexesToCheck = 8;
- for (int i = 0; i < allDirs.Length; i++)
- {
- // makes a substring with 'indexesToCheck' amount of characters from the directory name
- string dirStart = allDirs[i].Substring(path.Length + 2, indexesToCheck);
- // the +2 is because the path allDirs[i] has an additional '//'
- // goes trough every dir above i and compares it to 'dirStart'
- for (int j = i + 1; j < allDirs.Length; j++)
- {
- // makes another substring
- string otherDirStart = allDirs[j].Substring(path.Length + 2, indexesToCheck);
- // if they match, the dir of index i will be deleted later on
- if (dirStart == otherDirStart)
- {
- thingsToDel.Add(allDirs[i]);
- break;
- }
- }
- }
- // deletes everything in 'thingsToDel'
- foreach (string thing in thingsToDel)
- {
- Directory.Delete(thing, true);
- // the true stands for deleting directories, even if they have subdirectories/files
- }
- thingsToDel.Clear();
- // delete files that do not match my needs //
- string[] allFiles = Directory.GetFiles(path, "*.osu", SearchOption.AllDirectories);
- // .osu files are comparable to .ini files
- // if true, the file will not be deleted
- bool fileIsCorrect = false;
- // if true, the file has mania as mode and needs an aditional check
- bool modeIsMania = false;
- // checks for each file, if it should be deleted
- foreach (string file in allFiles)
- {
- fileIsCorrect = false;
- modeIsMania = false;
- string[] lines = File.ReadAllLines(file);
- foreach (string line in lines)
- {
- // format is: Mode = (number between 0 and 3)
- if (line.Contains("Mode"))
- {
- if (line.Contains("0")) // change to your gamemode/s (add || line.Contains("x") to add one)
- {
- fileIsCorrect = true;
- }
- else if (line.Contains("3")) // delete these 4 rows if you don't want mania maps
- {
- modeIsMania = true;
- }
- }
- else if (modeIsMania && (line.Contains("CircleSize") && (line.Contains("4") || line.Contains("7") || line.Contains("10"))))
- { // circlesize is an additional check that only mode mania/3 needs
- fileIsCorrect = true;
- }
- }
- if (!fileIsCorrect)
- {
- thingsToDel.Add(file);
- }
- }
- foreach (string thing in thingsToDel)
- {
- File.Delete(thing);
- }
- thingsToDel.Clear();
- // delete directories without .osu files //
- allDirs = Directory.GetDirectories(path);
- foreach (string dir in allDirs)
- {
- // if a dir does not have at least 1 .osu file in it, it will be delete later
- if (Directory.GetFiles(dir, "*.osu").Length == 0)
- {
- thingsToDel.Add(dir);
- }
- }
- foreach (string thing in thingsToDel)
- {
- Directory.Delete(thing, true);
- }
- thingsToDel.Clear();
- // end of program //
- Console.WriteLine(
- "The Program is finished!n" +
- "Press any key to exit...");
- Console.ReadKey();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement