//static void Unmount() //{ // Console.WriteLine("Unmounting G:"); // StartProcess(@"C:\Program Files\PowerISO\piso.exe", "unmount G:"); //} public static void CategorizeLibraryFolders() { var folders = Directory.EnumerateDirectories(Paths.OutputPath, "*", SearchOption.TopDirectoryOnly); foreach (var folder in folders) { if (Path.GetFileName(folder) == "_Kontakt" || Path.GetFileName(folder) == "_Loops") { continue; } var files = Directory.EnumerateFiles(folder, "*.nki", SearchOption.AllDirectories).ToArray(); if (files.Length > 0) { Directory.Move(folder, Paths.OutputPath + @"\_Kontakt\" + Path.GetFileName(folder)); } else { files = Directory.EnumerateFiles(folder, "*.iso", SearchOption.AllDirectories).ToArray(); files = files.Concat(Directory.EnumerateFiles(folder, "*.bin", SearchOption.AllDirectories)).ToArray(); if (files.Length > 0) { Directory.Move(folder, Paths.OutputPath + @"\_Iso\" + Path.GetFileName(folder)); } else { Directory.Move(folder, Paths.OutputPath + @"\_Loops\" + Path.GetFileName(folder)); } } } }
public void TestEnumerateDirectoriesWithSearchWithNoResults() { var randomFileName = Path.GetRandomFileName(); var tempLongPathFilename = Path.Combine(uncDirectory, randomFileName); Directory.CreateDirectory(tempLongPathFilename); try { var dirs = Directory.EnumerateDirectories(uncDirectory, "gibberish").ToArray(); Assert.AreEqual(0, dirs.Length); Assert.IsFalse(dirs.Contains(tempLongPathFilename)); } finally { Directory.Delete(tempLongPathFilename); } }
public void TestRecursiveEnumerateDirectoriesWithSingleSubsetSearch() { var randomFileName = "TestRecursiveEnumerateDirectoriesWithSubsetSearch"; var tempLongPathFilename = Path.Combine(uncDirectory, randomFileName); Directory.CreateDirectory(tempLongPathFilename); try { var dirs = Directory.EnumerateDirectories(uncDirectory, "T*", SearchOption.AllDirectories).ToArray(); Assert.AreEqual(1, dirs.Length); Assert.IsTrue(dirs.Contains(tempLongPathFilename)); } finally { Directory.Delete(tempLongPathFilename); } }
public void TestEnumerateDirectories() { var randomFileName = Path.GetRandomFileName(); var tempPath = Path.Combine(uncDirectory, randomFileName); Directory.CreateDirectory(tempPath); try { var dirs = Directory.EnumerateDirectories(uncDirectory).ToArray(); Assert.AreEqual(1, dirs.Length); Assert.IsTrue(dirs.Contains(tempPath)); } finally { Directory.Delete(tempPath); } }
public static void FixLibraryFolders() { var folders = Directory.EnumerateDirectories(Paths.OutputPath, "*", SearchOption.TopDirectoryOnly); foreach (var folder in folders) { var name = Path.GetFileName(folder); var oldName = name; name = Regex.Replace(name, @"\b(HYBRID|DYNAMiCS|PROPER|VSTi|RTAS|CHAOS|AMPLiFY|AU|MATRiX|DVDR|WAV|AiR|ArCADE|VR|CDDA|PAD|MiDi|CoBaLT|DiSCOVER)\b", ""); name = Regex.Replace(name, @"\b(WareZ Audio info|Kontakt|Audiostrike|SYNTHiC4TE|AUDIOXiMiK|MAGNETRiXX|TZ7iSO|KLI|DVDriSO|DVD9|KRock|ACiD|REX|RMX|SynthX|AiFF|Apple Loops|AiRISO|MULTiFORMAT|AudioP2P|GHOSTiSO|REX2|DXi|HYBRiD|AKAI|ALFiSO)\b", "", RegexOptions.IgnoreCase); name = Regex.Replace(name, @" +", " "); if (name != oldName && !Directory.Exists(Path.GetDirectoryName(folder) + @"\" + name)) { File.Move(folder, Path.GetDirectoryName(folder) + @"\" + name); } } }
static void ProcessFolder(string rootPath, string baseFolder, string destFolder, bool canMove, bool preservePaths, string extraPath = "") { var folder = baseFolder; var files = Directory.EnumerateFiles(folder, "*").Where(f => Path.GetExtension(f) != ".txt" && Path.GetExtension(f) != ".nfo" && Path.GetExtension(f) != ".sfv").ToArray(); while (!preservePaths) // Not a true while, preserve paths does not change. { var subFolders = Directory.EnumerateDirectories(folder).ToArray(); if (files.Length == 0 && subFolders.Length == 1) { folder = subFolders[0]; } else { break; } files = Directory.EnumerateFiles(folder, "*").Where(f => Path.GetExtension(f) != ".txt" && Path.GetExtension(f) != ".nfo" && Path.GetExtension(f) != ".sfv").ToArray(); } //files = Directory.EnumerateFiles(folder, "*", SearchOption.AllDirectories).ToArray(); var archiveFiles = GetArchiveFiles(files); archiveFiles.ForEach(archive => ProcessArchive(rootPath, Path.GetDirectoryName(archive), archive, files, destFolder)); var names = folder.Substring(rootPath.Length).Split(Path.DirectorySeparatorChar); var name = names.FirstOrDefault(n => Regex.IsMatch(n, "KONTAKT", RegexOptions.IgnoreCase)) ?? names[0]; //if ((folder + "\\").StartsWith(string.Format("{0}\\{1}\\", baseFolder, name))) // name = ""; //name = Regex.Replace(name, @"\.(rar|r00|zip|iso)$", "", RegexOptions.IgnoreCase); name = Regex.Replace(name, @"\.(rar|r00|zip)$", "", RegexOptions.IgnoreCase); name = Regex.Replace(name, @"\.part1", "", RegexOptions.IgnoreCase); name = Regex.Replace(name, @"\.part01", "", RegexOptions.IgnoreCase); name = Regex.Replace(name, "-", " "); name = Regex.Replace(name, @"([a-z ])\.+([\w ])", "$1 $2", RegexOptions.IgnoreCase); // Remove dots but leave those that are between digits. name = Regex.Replace(name, @"([\w ])\.+([a-z ])", "$1 $2", RegexOptions.IgnoreCase); name = Regex.Replace(name, @"\b(HYBRID|DYNAMiCS|PROPER|VSTi|RTAS|CHAOS|AMPLiFY|AU|MATRiX|DVDR|WAV|AiR|ArCADE|VR|CDDA|PAD|MiDi|CoBaLT|DiSCOVER)\b", ""); name = Regex.Replace(name, @"\b(WareZ Audio info|Kontakt|Audiostrike|SYNTHiC4TE|AUDIOXiMiK|MAGNETRiXX|TZ7iSO|KLI|DVDriSO|DVD9|KRock|ACiD|REX|RMX|SynthX|AiFF|Apple Loops|AiRISO|MULTiFORMAT|AudioP2P|GHOSTiSO|REX2|DXi|HYBRiD|AKAI|ALFiSO)\b", "", RegexOptions.IgnoreCase); //name = Regex.Replace(name, "(HYBRID|DYNAMiCS|PROPER|VSTi|RTAS|CHAOS|AMPLiFY| AU |MATRiX)", ""); //name = Regex.Replace(name, "(WareZ Audio info|Kontakt|Audiostrike|SYNTHiC4TE|AUDIOXiMiK||MAGNETRiXX)", "", RegexOptions.IgnoreCase); name = Regex.Replace(name, @" +", " "); name = name.Trim(' ', '-'); var destPath = $"{destFolder}\\{name}{extraPath}"; CopyFiles(folder, destPath, canMove, false); }
static void CopyFiles(string source, string dest, bool move, bool includeArchives = true) { if (move) { MarkFolderWritable(source); } MarkFolderWritable(dest); Console.WriteLine("{0} {1} => {2}", move ? "Moving" : "Copying", source, dest); source = source.TrimEnd('\\'); dest = dest.TrimEnd('\\'); if (!Directory.Exists(dest)) { Directory.CreateDirectory(dest); } Directory.EnumerateDirectories(source, "*", SearchOption.AllDirectories).Select(d => d.Replace(source, dest)).ForEach(path => Directory.CreateDirectory(path)); foreach (var file in Directory.EnumerateFiles(source, "*", SearchOption.AllDirectories).Where(f => Path.GetExtension(f) != ".nfo" && !Regex.IsMatch(Path.GetFileName(f), "All.Collection.Upload|WareZ-Audio", RegexOptions.IgnoreCase)).ToArray()) { if (Path.GetExtension(file) == ".sfv") { continue; } //if (!includeArchives && Regex.IsMatch(Path.GetExtension(file), @"\.(rar|r\d+|zip|iso)")) if (!includeArchives && Path.GetDirectoryName(file) == source && Regex.IsMatch(Path.GetExtension(file), @"\.(rar|r\d+|zip)")) { continue; } var newFile = file.Replace(source, dest); if (move) { if (File.Exists(newFile)) { File.Delete(newFile); } File.Move(file, newFile); } else { File.Copy(file, newFile, true); } } }
public void TestDirectoryEnumerateDirectoriesNearMaxPathLimit() { var uncPathNearMaxPathLimit = Path.Combine(uncDirectory, new string('x', Pri.LongPath.NativeMethods.MAX_PATH - uncDirectory.Length - 2)); Directory.CreateDirectory(uncPathNearMaxPathLimit.Replace(uncDirectory, directory)); var uncPathAboveMaxPathLimit = Path.Combine(uncPathNearMaxPathLimit, "wibble"); Directory.CreateDirectory(uncPathAboveMaxPathLimit); Assert.That(Directory.Exists(uncPathNearMaxPathLimit)); Assert.That(Directory.Exists(uncPathAboveMaxPathLimit)); // there should be one subdirectory inside almostLongPath var subDirs = Directory.EnumerateDirectories(uncPathNearMaxPathLimit).ToArray(); Directory.Delete(uncPathAboveMaxPathLimit); Directory.Delete(uncPathNearMaxPathLimit); Assert.That(subDirs.Length, Is.EqualTo(1)); }
public static IEnumerable <string> EnumerateDirectories(string path, string searchPattern, SearchOption options) { return(Directory.EnumerateDirectories(path, searchPattern, options)); }
public static IEnumerable <string> EnumerateDirectories(string path, string searchPattern) { return(Directory.EnumerateDirectories(path, searchPattern)); }
public static IEnumerable <string> EnumerateDirectories(string path) { return(Directory.EnumerateDirectories(path)); }