From d05a88d2ee726b2485bae0ebbfc86de01ad13934 Mon Sep 17 00:00:00 2001 From: ed Date: Sat, 4 Oct 2025 11:53:59 +0000 Subject: [PATCH] add rename counters; closes #854 --- README.md | 2 ++ copyparty/web/browser.js | 7 +++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 97232c9c..f71bfb65 100644 --- a/README.md +++ b/README.md @@ -998,6 +998,8 @@ available functions: * `$lpad(text, length, pad_char)` * `$rpad(text, length, pad_char)` +two counters are available; `.n.s` is the nth file in the selection, and `.n.d` the nth file in the folder, for example rename-output `file(.n.d).(ext)` gives `file5.bin`, and `beach-$lpad((.n.s),3,0).(ext)` is `beach-017.jpg` + so, say you have a file named [`meganeko - Eclipse - 07 Sirius A.mp3`](https://www.youtube.com/watch?v=-dtb0vDPruI) (absolutely fantastic album btw) and the tags are: `Album:Eclipse`, `Artist:meganeko`, `Title:Sirius A`, `tn:7` diff --git a/copyparty/web/browser.js b/copyparty/web/browser.js index 3e8ef1da..996b1757 100644 --- a/copyparty/web/browser.js +++ b/copyparty/web/browser.js @@ -15933,7 +15933,8 @@ var fileman = (function () { r.rename = function (e) { ev(e); - var sel = msel.getsel(); + var sel = msel.getsel(), + all = msel.all; if (!sel.length) return toast.err(3, L.fr_emore); @@ -15957,9 +15958,11 @@ var fileman = (function () { return toast.err(0, esc('bug:\n' + base + '\n' + vsp[0])); var vars = ft2dict(ebi(sel[a].id).closest('tr')); - mkeys = vars[1].concat(vars[2]); + mkeys = [".n.d", ".n.s"].concat(vars[1], vars[2]); var md = vars[0]; + md[".n.s"] = '' + (1 + a); + md[".n.d"] = '' + (1 + all.indexOf(sel[a])); for (var k in md) { if (!md.hasOwnProperty(k)) continue;