0

I'm stuck, trying to get the name of image after uploaded it.

C:\work\assets\pic_items\06c1dd6b-5173-47b6-be09-f5c76866996d.PNG

I always get this result all I want is just the last 06c1dd6b-5173-47b6-be09-f5c76866996d.PNG

I use .split but it doesn't seems to work

picture_path = uploadedFiles[0].fd.z[z.length-1].split('.');
1

3 Answers 3

0

Try this:

var filePath = 'C:\\work\\assets\\pic_items\\06c1dd6b-5173-47b6-be09-f5c76866996d.PNG';
var fileName = filePath.split('\\').pop();
console.log(fileName) // 06c1dd6b-5173-47b6-be09-f5c76866996d.PNG

This will break the path into parts and then use pop to grab the last entry in the array, which is the filename.

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

Comments

0

If you have C:\work\assets\pic_items\06c1dd6b-5173-47b6-be09-f5c76866996d.PNG and want 06c1dd6b-5173-47b6-be09-f5c76866996d.PNG, try:

var fileParts = filePath.split('\\');
filename = fileParts[fileParts.length - 1];

Comments

0

You'll have to escape the backslashes as they're escape characters themselves:

var str = 'C:\\work\\assets\\pic_items\\06c1dd6b-5173-47b6-be09-f5c76866996d.PNG';
var li = str.lastIndexOf('\\'); // last index of backslash
console.log(str.slice(li + 1)) // 06c1dd6b-5173-47b6-be09-f5c76866996d.PNG

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.