using System; using System.Collections.Generic; using System.IO; namespace Sony.Filtr.Tasks.Tasks.Spotify { public class NewPlaylistsFromFolderReader : NewPlaylistsReader { public readonly string FolderPath; public readonly string FileSearchPattern; public NewPlaylistsFromFolderReader(string folderPath, string fileSearchPattern) { if (!Directory.Exists(folderPath)) { throw new ArgumentException($"Could not find folder '{folderPath}'"); } this.FolderPath = folderPath; this.FileSearchPattern = fileSearchPattern; } public override IEnumerable GetPlaylistIds() { foreach (var file in this.GetFiles()) { foreach (var id in File.ReadAllLines(file)) { yield return id; } this.MarkAsProcessed(file); } } private string[] GetFiles() { return Directory.GetFiles(this.FolderPath, this.FileSearchPattern); } private void MarkAsProcessed(string file) { string newFileName = $"PROCESSED_{Path.GetFileNameWithoutExtension(file)}{Path.GetExtension(file)}"; File.Move(file, Path.Combine(Path.GetDirectoryName(file), newFileName)); } } }