#1 : 28/05-20 21:24 Omar
Posts: 1
|
I have 4,000+ files with the following name pattern:
13182496371 13182510187 13182558569-001 13182558569-002 13182558569-003 13182558569-004 13182809809 I want add a 3-character random name and keep groups/sets: AWD FWG GHF-001 GHF-002 GHF-003 GHF-004 HEJ Any ideas? I know I have to use <Rand Str:3> but it does not keep groups. Thanks! |
#2 : 29/05-20 16:41 David Lee
Posts: 1125
|
You will need to use a script to keep track of the previous filenames.
A simple answer to your problem is the script: suffix = item.name.match(/-\d{3}$/); n = suffix * -1; if (n < 2) {txt = app.parseTags('<Rand Str:3>')} return txt; You must ensure that the files are sorted in ascending order and set the Name collision rule to "Append number" and separator to "-". The .match method extracts the value of the numeric suffix. If there is no suffix or it has the value "-001" then the tag "<Rand Str:3>" is used to define a new filename and this value is stored in the variable txt. If the suffix is "-002" then the previously saved value of txt is used as a filename. The suffix is recreated by the collision rule. However there is a problem with this solution. Whilst <Rand Str> will produce a pseudo-random string each time it runs, you need to be aware that Advanced Renamer does NOT keep track of which strings have been used. Hence there is a possibility of duplicates - particularly if you have a large number of filenames - since there are only 17,576 possible permutations of a three-letter string. You must keep track of which permutations have already been used and keep generating new permutations until <Rand Str> returns an unused value. The following script should solve the problem: In the Pre batch script: var test = []; for (j = 0; j < 17575; j++) { test[j] = 0; } function getText() { do { n1 = Math.floor(Math.random() * 26); n2 = Math.floor(Math.random() * 26); n3 = Math.floor(Math.random() * 26); n = n1 + (n2 + n3 * 26) * 26; } while (test[n]); test[n] = 1; return String.fromCharCode(n1 + 97) + String.fromCharCode(n2 + 97) + String.fromCharCode(n3 + 97); } and in the main script window: suffix = item.name.match(/-\d{3}$/); n = suffix * -1; if (n < 2) {txt = getText()} name = txt; if (suffix) {name = name + suffix} return name; |
#3 : 02/06-20 19:54 Ankita Goel
Posts: 1
|
Reply to #1:
hey check https://webinarwall.com/index.php |