Skip to content

Instantly share code, notes, and snippets.

@aviatrix
Last active August 27, 2016 13:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aviatrix/ec77b95214c783ee95913de840a8bd68 to your computer and use it in GitHub Desktop.
Save aviatrix/ec77b95214c783ee95913de840a8bd68 to your computer and use it in GitHub Desktop.
<Query Kind="Statements">
<Reference>&lt;RuntimeDirectory&gt;\System.Dynamic.dll</Reference>
<Reference>&lt;RuntimeDirectory&gt;\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