0
let NewName= params.strdocumentname + "(" + results.rows[0].arrayfilecount+ ")";
strdocumentname = params.strdocumentname = NewName;

the current output is Jayson.png(2)

desired output Jayson (2).png

How do i do that using the code above?

2 Answers 2

2

Use the following code:-

const path = require('path');
const extension= path.extname(params.strdocumentname);
const name= params.strdocumentname.replace(extension,"(" + results.rows[0].arrayfilecount+ ")");
const newName = name + extension;

Hope it helps Thanks

Sign up to request clarification or add additional context in comments.

Comments

1

I think your params.strdocumentname contains the extension of the file also. Try this code;

let [fileName, extension] = params.strdocumentname.split('.');
let NewName= fileName + "(" + results.rows[0].arrayfilecount+ ")." + extension;
strdocumentname = params.strdocumentname = NewName;

see working fiddle

let mockFileName = "abc.png"
let mockArrayCount = '1'

let [fileName, extension] = mockFileName.split('.');
let NewName= fileName + "(" + mockArrayCount+ ")." + extension;

console.log(NewName)
alert(NewName)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.