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 <noreply@anthropic.com>
This commit is contained in:
@@ -28,8 +28,8 @@ public class ArchiveService
|
|||||||
var jsonDirectory = Path.GetDirectoryName(jsonFilePath)!;
|
var jsonDirectory = Path.GetDirectoryName(jsonFilePath)!;
|
||||||
var filesDirectory = GetFilesDirectoryPath(jsonFilePath);
|
var filesDirectory = GetFilesDirectoryPath(jsonFilePath);
|
||||||
|
|
||||||
// Create archive subdirectory based on date
|
// Create archive subdirectory based on export date from filename
|
||||||
var archiveSubdir = DateTime.Now.ToString("yyyy-MM-dd");
|
var archiveSubdir = GetExportDateFromFilename(jsonFileName) ?? DateTime.Now.ToString("yyyy-MM-dd");
|
||||||
var archivePath = Path.Combine(archiveRoot, archiveSubdir);
|
var archivePath = Path.Combine(archiveRoot, archiveSubdir);
|
||||||
Directory.CreateDirectory(archivePath);
|
Directory.CreateDirectory(archivePath);
|
||||||
|
|
||||||
@@ -152,6 +152,26 @@ public class ArchiveService
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Extracts the export date from a filename like "2026-01-20.json".
|
||||||
|
/// Returns null if the filename doesn't match the expected pattern.
|
||||||
|
/// </summary>
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Moves a file, falling back to copy+delete for cross-device moves.
|
/// Moves a file, falling back to copy+delete for cross-device moves.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user