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.
///