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

Rename files

Advocate ,
Mar 27, 2018 Mar 27, 2018

Copy link to clipboard

Copied

Rename files

I have a test.jsx file on the desktop

I would like to rename it to test1.jsx

that would be great

if it is possible to have a sequential or random number to be added

after the writing test_sequential.jsx

TOPICS
Actions and scripting

Views

754

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

Guide , Mar 27, 2018 Mar 27, 2018

Like this?

main();

function main(){

var doc = File(Folder.desktop + "/test.jsx");

if(!doc.exists) return;

var Name = "test";

var fileList= Folder.desktop.getFiles("Test*.jsx").sort().reverse();

var Suffix = 0;

if(fileList.length){

    Suffix = Number(fileList[0].name.replace(/\.[^\.]+$/, '').match(/\d+$/));

}

Suffix= zeroPad(Suffix + 1, 4);

doc.rename(Name + "_" + Suffix + ".jsx");

}

function zeroPad(n, s) {

   n = n.toString();

   while (n.length < s)  n = '0' + n;

   return n;

};

Votes

Translate

Translate
Adobe
Guide ,
Mar 27, 2018 Mar 27, 2018

Copy link to clipboard

Copied

Like this?

main();

function main(){

var doc = File(Folder.desktop + "/test.jsx");

if(!doc.exists) return;

var Name = "test";

var fileList= Folder.desktop.getFiles("Test*.jsx").sort().reverse();

var Suffix = 0;

if(fileList.length){

    Suffix = Number(fileList[0].name.replace(/\.[^\.]+$/, '').match(/\d+$/));

}

Suffix= zeroPad(Suffix + 1, 4);

doc.rename(Name + "_" + Suffix + ".jsx");

}

function zeroPad(n, s) {

   n = n.toString();

   while (n.length < s)  n = '0' + n;

   return n;

};

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
Advocate ,
Mar 28, 2018 Mar 28, 2018

Copy link to clipboard

Copied

Thanks SuperMerlin

And if I wanted to delete the test.jsx file

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
Guide ,
Mar 28, 2018 Mar 28, 2018

Copy link to clipboard

Copied

LATEST

var doc = File(Folder.desktop + "/test.jsx");

if(doc.exists) doc.remove();

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