Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Rename multiple files

Explorer ,
Mar 02, 2022 Mar 02, 2022

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 

TOPICS
Scripting
3.0K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Mar 02, 2022 Mar 02, 2022

 

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])})

 

Translate
LEGEND ,
Mar 16, 2022 Mar 16, 2022

Nope, make a change of similar part in my original code.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Mar 16, 2022 Mar 16, 2022

ok 🙂 very confused now...

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 16, 2022 Mar 16, 2022

When in Br you're in a folder with files use corrected version with a shortcut...

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 16, 2022 Mar 16, 2022

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 02, 2022 Mar 02, 2022

Great job with the script as usual @Kukurykus !

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Mar 31, 2022 Mar 31, 2022

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: 

0001.jpg

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 31, 2022 Mar 31, 2022
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])
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Apr 01, 2022 Apr 01, 2022

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 01, 2022 Apr 01, 2022

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--

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Apr 01, 2022 Apr 01, 2022
LATEST

Now yes, it worked 100% Perfect! @Kukurykus  you a genius. Thank you for kindly fulfilling my request.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines