#1 : 19/01-22 07:32 MaxEnrik
Posts: 12
|
Script belongs to @davidlee.
Pre-batch Script: var filesInFolder = {}; Main Script: folder = app.parseTags("<DirName:1>"); if(num = filesInFolder[folder]) num++; else num = 1; filesInFolder[folder] = num; return item.name + " " + ("00" + num).slice(-3); My examples: Less than 9 files Old_Filename_21589 ... Old_Filename_56387 Less than 99 files Old_Filename_63215 ... Old_Filename_87145 Less than 999 files Old_Filename_42589 ... Old_Filename_36999 Expect: Less than 9 files Filenames_1 ... Filenames_9 Less than 99 files Filenames_01 ... Filenames_99 Less than 999 files Filenames_001 ... Filenames_999 There are various numbers of files in folders. In this case using 'return item.name + " " + ("00" + num).slice(-3);' for less than 9 files is not necessary. Now I have to modify the line of code like this 'return item.name + " " + ("" + num).slice(-1);' for less than 9 files. And for folders that have less than 99 files. Now I have to use the line of code like this 'return item.name + " " + ("0" + num).slice(-2);' and so on. My question: Is it possible to use this '( app.parseTags("<Inc Nr:1>") )' instead of '("00" + num).slice(-3)' in Main Script? (Sorry about my poor English.) |
#2 : 19/01-22 12:42 David Lee
Posts: 1125
|
The <Inc Nr:1> tag will renumber all the files in the list sequentially irrespective of which folder they are in.
You will need to save the number of digits required for each folder in another object: Pre-batch Script: var filesInFolder = {}; var digits = {}; Main Script: folder = app.parseTags("<DirName:1>"); if(num = filesInFolder[folder]) num++; else { num = 1; digits[folder] = Math.ceil(Math.log10(1 + 1*app.parseTags('<Num Files>'))); } filesInFolder[folder] = num; return item.newBasename + " " + ("0000" + num).slice(-digits[folder]); I have changed the return statement to use item.newBasename so that it will retain changes you may have made in any previous methods - whereas item.name will always return the original filename in the List. |
#3 : 19/01-22 13:27 MaxEnrik
Posts: 12
|
Reply to #2:
Impressive! That is what I want. Thank you so much more! |