From 76e9f23a6dd407de749c9a09f8a14252522ec564 Mon Sep 17 00:00:00 2001 From: ed Date: Sun, 5 Oct 2025 21:51:41 +0000 Subject: [PATCH] batch-rename: initial counter values --- README.md | 2 +- copyparty/web/browser.css | 2 ++ copyparty/web/browser.js | 27 ++++++++++++++++++++++++--- 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 921bba13..cf3370c4 100644 --- a/README.md +++ b/README.md @@ -1003,7 +1003,7 @@ 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` +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` and the initial value of each counter can be set in the textboxes underneath the preset dropdown so, diff --git a/copyparty/web/browser.css b/copyparty/web/browser.css index 0a0afc5c..25d417d2 100644 --- a/copyparty/web/browser.css +++ b/copyparty/web/browser.css @@ -1939,6 +1939,8 @@ html.y #tree.nowrap .ntree a+a:hover { #rui td input[type="text"] { width: 100%; } +#rui #rn_n_d, +#rui #rn_n_s, #shui td.exs input[type="text"] { width: 3em; } diff --git a/copyparty/web/browser.js b/copyparty/web/browser.js index 030a7d97..880d295e 100644 --- a/copyparty/web/browser.js +++ b/copyparty/web/browser.js @@ -15944,11 +15944,16 @@ var fileman = (function () { var f = [], sn = ++r.sn, base = vsplit(sel[0].vp)[0], + s2d = {}, mkeys; r.f = f; + r.n_s = 1; + r.n_d = 1; for (var a = 0; a < sel.length; a++) { + s2d[a] = all.indexOf(sel[a]); + var vp = sel[a].vp; if (vp.endsWith('/')) vp = vp.slice(0, -1); @@ -15961,8 +15966,7 @@ var fileman = (function () { 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])); + md[".n.s"] = md[".n.d"] = 0; for (var k in md) { if (!md.hasOwnProperty(k)) continue; @@ -16009,6 +16013,10 @@ var fileman = (function () { 'regex', 'format', 'preset', + 'num0', + 'n.d=  ', + 'n.s=', + '', '', '', '', @@ -16153,6 +16161,15 @@ var fileman = (function () { }; spresets(); + ebi('rn_n_s').oninput = function () { + r.n_s = parseInt(this.value || '1'); + ifmt.oninput(); + }; + ebi('rn_n_d').oninput = function () { + r.n_d = parseInt(this.value || '1'); + ifmt.oninput(); + }; + ire.onkeydown = ifmt.onkeydown = function (e) { var k = (e.key || e.code) + ''; @@ -16182,14 +16199,18 @@ var fileman = (function () { for (var a = 0; a < f.length; a++) { var m = re ? re.exec(f[a].ofn) : null, + d = f[a].md, ok, txt = ''; + d[".n.s"] = d["n.s"] = '' + (r.n_s + a); + d[".n.d"] = d["n.d"] = '' + (r.n_d + s2d[a]); + if (re && !m) { txt = 'regex did not match'; ok = false; } else { - var ret = fmt_ren(m, f[a].md, fmt); + var ret = fmt_ren(m, d, fmt); ok = ret[0]; txt = ret[1]; }