How to get the file name from a full path using JavaScript?

前端 未结 18 1341
生来不讨喜
生来不讨喜 2020-11-22 11:01

Is there a way that I can get the last value (based on the \'\\\' symbol) from a full path?

Example:

C:\\Documents and Settings\\img\\recycled log.jpg<

18条回答
  •  说谎
    说谎 (楼主)
    2020-11-22 11:56

    Not more concise than nickf's answer, but this one directly "extracts" the answer instead of replacing unwanted parts with an empty string:

    var filename = /([^\\]+)$/.exec(fullPath)[1];
    

提交回复
热议问题