Copy link to clipboard
Copied
Hi guys.
I need to rename a lot of files sequentially that have a pattern like:
keep the filename, but change the 5 digits to single digits:
AJKGHD-BK-76357.jpg
AJKGHD-BK-76358.jpg
AJKGHD-BK-76359.jpg
to
AJKGHD-BK-1.jpg
AJKGHD-BK-2.jpg
AJKGHD-BK-3.jpg
and or
KGH-WH-36286.jpg
KGH-WH-36287.jpg
KGH-WH-36288.jpg
to
KGH-WH-1.jpg
KGH-WH-2.jpg
KGH-WH-3.jpg
Hope that makes sense. Any help is appreciated. Thank you
objct = {}, File('~/desktop/folder')
.getFiles(function(v){k0 = (key = decodeURI(v.name)
.split(/\d+/))[0], v.rename(k0 + eval('objct[k0] '
+ ({1: '', 0: '+'})[+!objct[k0]] + '= 1') + key[1])})
Copy link to clipboard
Copied
Nope, make a change of similar part in my original code.
Copy link to clipboard
Copied
ok 🙂 very confused now...
Copy link to clipboard
Copied
When in Br you're in a folder with files use corrected version with a shortcut...
Copy link to clipboard
Copied
No, not using my code addition, adding the new code to the original code:
#target bridge
objct = {}, File(app.document.presentationPath)
.getFiles(function(v){k0 = (key = decodeURI(v.name)
.split(/\d+/))[0], v.rename(k0 + eval('objct[k0] '
+ ({1: '', 0: '+'})[+!objct[k0]] + '= 1') + key[1])})
The files don't have to be selected in Bridge, just have the appropriate folder open/browsed and then run the script.
Copy link to clipboard
Copied
Great job with the script as usual @Kukurykus !
Copy link to clipboard
Copied
Oi @Kukurykus, @Stephen Marsh cara, esse seu script é muito interessante e bastante útil, ótimo trabalho.
Em outra situação, como renomear todos os arquivos, exceto arquivos com nomes: "Capa" ou "Img".
Geralmente são arquivos .jpg, independentemente de haver ou não um sufixo no nome do arquivo original.
ex:
Copy link to clipboard
Copied
lngth = (fls = File('~/desktop/folder').getFiles(/Text/)).length; while(fls.length) (fle = fls.shift())
.rename('Pad_' + ('0' + (lngth - fls.length)).slice(-2) + fle.name.split(/.+?(?=\..{3,4}$)/)[1])
Copy link to clipboard
Copied
Thank you @Kukurykus , you are a genius and very nice! Wouldn't it be better to rename files with any name except those with the cited names ("Capa" or "Img")?. Thanks man for your huge contribution.
Copy link to clipboard
Copied
I don't know whether it wouldn't be better, I did what you wanted for only Text Files, didn't I?
l=(fls=File('~/desktop/folder').getFiles()).length; while(fls.length)
!/^(Capa|Img)\..{3,4}$/.test(nme = (fle = fls.shift()).name)
? fle.rename('Pad_' + ('0' + (l - fls.length)).slice(-2)
+ fle.name.split(/.+?(?=\..{3,4}$)/)[1]) : l--
Copy link to clipboard
Copied
Now yes, it worked 100% Perfect! @Kukurykus you a genius. Thank you for kindly fulfilling my request.