1

i want to make the filename+spaces=211 characters but the problem is that if the file name characters = 30

i would need 181 spaces

while if file name characters = 80

i would need 131 spaces

i have tried advanced renamer

tags options + spaces .

<Name>                                                                                                                                                                                                                

.. and even this script in the scripts section

var maxLength = 25;
var name = item.name;
var date = app.parseTags("<Year Modified><Month Modified><Day Modified>");
var numSpaces = maxLength - name.length - date.length;
var spaces = "";
for (i = 0; i < numSpaces; i++) spaces += " ";
return name + spaces + date; 

but it give me this error name is not defined in the line 3

mina nageh
  • 143
  • 2
  • 2
  • 13
  • What is the value of numSpaces in your example above before you use the for loop? Also looks like you have a typo, (var i = 0;) ==> you are missing the var in your forloop. – Spangle Feb 05 '19 at 03:04
  • If you fix that typo your code will word. – Spangle Feb 05 '19 at 03:17
  • Possible duplicate of [Is there a JavaScript function that can pad a string to get to a determined length?](https://stackoverflow.com/questions/2686855/is-there-a-javascript-function-that-can-pad-a-string-to-get-to-a-determined-leng) – Heretic Monkey Feb 07 '19 at 22:04

2 Answers2

0

You could use String#padEnd(), to add whitespaces to the end of your filename strings so that the resulting string has a minimum length a specified by you.

Consider the snippet below until where fileNameA.padEnd(211) returns a new string with the same leading characters as fileNameA, but with whitespaces padding the remainder of the string such that the string has length 211:

const fileNameA = 'your file name';
const fileNameB = 'some other big file name';

const paddedFileNameA = fileNameA.padEnd(211);
const paddedFileNameB = fileNameB.padEnd(211);

console.log(`
paddedFileNameA:
"${paddedFileNameA}"
length of paddedFileNameA: ${paddedFileNameA.length}
`)
console.log(`
paddedFileNameB:
"${paddedFileNameB}"
length of paddedFileNameB: ${paddedFileNameB.length}
`)

Update

I'm not familiar with the scripting feature set in Advanced Renamer, however you might find this works for you:

/*
Set length to 211
*/
var maxLength = 211; 
var name = item ? item.name : '';
var date = app.parseTags("<Year Modified><Month Modified><Day Modified>");

/*
Ensure variables are not undefined or null
*/
if(!name) {
    name = '';
}
if(!date) {
    date = '';
}

/*
Construct result string
*/
var result = name;
for (i = 0; i < (maxLength - (name.length + date.length)); i++) {
    result += ' ';
}
result += date;

return result;
Dacre Denny
  • 29,664
  • 5
  • 45
  • 65
0

the script that works using advanced Renamer

var maxLength = 222;
var name = item.name;
var date = app.parseTags("<Year Modified><Month Modified><Day Modified>");
var numSpaces = maxLength - name.length - date.length;
var spaces = "";
for (i = 0; i < numSpaces; i++) spaces += " ";
return name + spaces + date;

credits David Lee from advanced Renamer forms

mina nageh
  • 143
  • 2
  • 2
  • 13
  • please note that "if you set the filename +extension to 227 characters then the rest of your file path including volume name must be shorter than 33 characters otherwise Windows will throw an error when you run the batch. " – mina nageh Feb 07 '19 at 22:16