Last active
August 27, 2016 13:28
-
-
Save aviatrix/ec77b95214c783ee95913de840a8bd68 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Query Kind="Statements"> | |
<Reference><RuntimeDirectory>\System.Dynamic.dll</Reference> | |
<Reference><RuntimeDirectory>\System.Dynamic.Runtime.dll</Reference> | |
<Namespace>System</Namespace> | |
<Namespace>System.Collections.Generic</Namespace> | |
</Query> | |
var sourceDir = @"d:\downloads\all shows\"; | |
var directories = Directory.GetDirectories(sourceDir,"*",SearchOption.TopDirectoryOnly); | |
var showPattern = @"\.?s\d{1,2}e\d{0,2}"; | |
foreach (var dir in directories.Where(x => Regex.IsMatch(x,showPattern,RegexOptions.IgnoreCase))) | |
{ | |
var seasonAndEpString = Regex.Match(dir,showPattern,RegexOptions.IgnoreCase); | |
var fodlerInfo = new DirectoryInfo(dir); | |
fodlerInfo.Name.Dump(); | |
var filteredName = (fodlerInfo.Name.Split(new[] { seasonAndEpString.Value},StringSplitOptions.RemoveEmptyEntries)).First(); | |
filteredName = filteredName.Replace('.',' ').Trim(); | |
filteredName.Dump(); | |
if (!Directory.Exists(sourceDir+filteredName)) | |
{ | |
Directory.CreateDirectory(sourceDir+filteredName); | |
} | |
$"attempting move to {sourceDir + filteredName + "\\" + fodlerInfo.Name + "\\"}".Dump(); | |
try | |
{ | |
Directory.Move(dir, sourceDir + filteredName + "\\" + fodlerInfo.Name + "\\"); | |
} | |
catch (Exception ex) | |
{ | |
ex.Dump(dir); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment