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

Rename multiple files

Explorer ,
Mar 02, 2022 Mar 02, 2022

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 

TOPICS
Scripting

Views

1.4K

Translate

Translate

Report

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

 

Votes

Translate

Translate
LEGEND ,
Mar 16, 2022 Mar 16, 2022

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

ok 🙂 very confused now...

 

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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

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.

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

Great job with the script as usual @Kukurykus !

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

Oi @Kukurykus@Stephen_A_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

 

Votes

Translate

Translate

Report

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

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

Votes

Translate

Translate

Report

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

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.

Votes

Translate

Translate

Report

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

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

 

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

LATEST

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

Votes

Translate

Translate

Report

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