From e55d656829f72d9e1206483094801155e1f07c8a Mon Sep 17 00:00:00 2001 From: Alex Vallee Date: Fri, 26 Feb 2021 10:52:03 -0500 Subject: [PATCH] Make filenames naturally sort by date. Included a useful powershell script to rename the old format to the new. --- logs.lua | 2 +- rename-logs.ps1 | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 rename-logs.ps1 diff --git a/logs.lua b/logs.lua index 3215f87..5636daf 100644 --- a/logs.lua +++ b/logs.lua @@ -112,7 +112,7 @@ ashita.register_event('incoming_text', function(mode, message, modifiedmode, mod -- Create the file name and ensure the path to it exists.. local d = os.date('*t'); - local n = string.format('%s_%.2u.%.2u.%.4u.log', name, d.month, d.day, d.year); + local n = string.format('%s_%.4u.%.2u.%.2u.log', name, d.year, d.month, d.day); local p = string.format('%s/%s/', AshitaCore:GetAshitaInstallPath(), 'chatlogs'); if (not ashita.file.dir_exists(p)) then ashita.file.create_dir(p); diff --git a/rename-logs.ps1 b/rename-logs.ps1 new file mode 100644 index 0000000..6a263bd --- /dev/null +++ b/rename-logs.ps1 @@ -0,0 +1,4 @@ +$Search ='^(?.+)_(?\d\d).(?\d\d).(?\d\d\d\d).(?.*)$' +$Replace ='${Name}_${Year}.${Month}.${Day}.${Ext}' + + Get-ChildItem | where {$_.name -match $Search} | Rename-Item -NewName {$_.name -replace $Search,$Replace} \ No newline at end of file