Created
October 26, 2018 14:17
-
-
Save KristofferK/6061818ebfaef35423b2a0a8e0b7051b 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
using System; | |
using System.Collections.Generic; | |
using System.IO; | |
using System.Linq; | |
using System.Text; | |
using System.Text.RegularExpressions; | |
using System.Threading.Tasks; | |
namespace LFLVRenamer | |
{ | |
class Program | |
{ | |
private const string DIRECTORY = @"D:\Deluge\LFLV\"; | |
private static Dictionary<string, int> episodeNo; | |
static void Main(string[] args) | |
{ | |
episodeNo = new Dictionary<string, int>(); | |
GetSeaonDirectories() | |
.SelectMany(GetFilesFromSeasonDirectory) | |
.ToList() | |
.ForEach(Print); | |
} | |
static IEnumerable<string> GetSeaonDirectories() | |
{ | |
return Directory.GetDirectories(DIRECTORY, "S0*"); | |
} | |
static IEnumerable<string> GetFilesFromSeasonDirectory(string directory) | |
{ | |
return Directory.GetFiles(directory); | |
} | |
static void Print(string file) | |
{ | |
var directory = file.Substring(0, file.LastIndexOf('\\') + 1); | |
if (!episodeNo.ContainsKey(directory)) | |
{ | |
episodeNo[directory] = 1; | |
} | |
var episodename = file.Substring(file.LastIndexOf('\\') + 1 + "LFLV Afsnit XX - ".Length); | |
var season = directory.Substring(directory.Length - 3, 2); | |
var episodeNoPadded = episodeNo[directory].ToString().PadLeft(2, '0'); | |
var newFilename = $"{directory}{season}x{episodeNoPadded} - {episodename}"; | |
Console.WriteLine(file); | |
Console.WriteLine(newFilename); | |
Console.WriteLine(); | |
episodeNo[directory]++; | |
File.Move(file, newFilename); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment