From a281f7f1e755add5f0447613e3b90907370d9b7d Mon Sep 17 00:00:00 2001 From: AJ Isaacs Date: Thu, 5 Feb 2026 23:20:17 -0500 Subject: [PATCH] Use export date from filename for archive subdirectory Extract the date from filenames like "2026-01-20.json" instead of using the current date, so archives are organized by export date rather than processing date. Co-Authored-By: Claude Opus 4.6 --- .../Services/ArchiveService.cs | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/DiscordArchiveManager/Services/ArchiveService.cs b/src/DiscordArchiveManager/Services/ArchiveService.cs index 4686d4d..1f65131 100644 --- a/src/DiscordArchiveManager/Services/ArchiveService.cs +++ b/src/DiscordArchiveManager/Services/ArchiveService.cs @@ -28,8 +28,8 @@ public class ArchiveService var jsonDirectory = Path.GetDirectoryName(jsonFilePath)!; var filesDirectory = GetFilesDirectoryPath(jsonFilePath); - // Create archive subdirectory based on date - var archiveSubdir = DateTime.Now.ToString("yyyy-MM-dd"); + // Create archive subdirectory based on export date from filename + var archiveSubdir = GetExportDateFromFilename(jsonFileName) ?? DateTime.Now.ToString("yyyy-MM-dd"); var archivePath = Path.Combine(archiveRoot, archiveSubdir); Directory.CreateDirectory(archivePath); @@ -152,6 +152,26 @@ public class ArchiveService } } + /// + /// Extracts the export date from a filename like "2026-01-20.json". + /// Returns null if the filename doesn't match the expected pattern. + /// + private static string? GetExportDateFromFilename(string filename) + { + var nameWithoutExtension = Path.GetFileNameWithoutExtension(filename); + if (DateTime.TryParseExact(nameWithoutExtension, "yyyy-MM-dd", null, System.Globalization.DateTimeStyles.None, out _)) + { + return nameWithoutExtension; + } + // Handle filenames with suffix like "2026-01-20_1.json" + var parts = nameWithoutExtension.Split('_'); + if (parts.Length > 0 && DateTime.TryParseExact(parts[0], "yyyy-MM-dd", null, System.Globalization.DateTimeStyles.None, out _)) + { + return parts[0]; + } + return null; + } + /// /// Moves a file, falling back to copy+delete for cross-device moves. ///