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
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;
};
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;
};
Copy link to clipboard
Copied
Thanks SuperMerlin
And if I wanted to delete the test.jsx file
Copy link to clipboard
Copied
var doc = File(Folder.desktop + "/test.jsx");
if(doc.exists) doc.remove();