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

前端 未结 18 1180
生来不讨喜
生来不讨喜 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:49

    In Node.js, you can use Path's parse module...

    var path = require('path');
    var file = '/home/user/dir/file.txt';
    
    var filename = path.parse(file).base;
    //=> 'file.txt'
    

提交回复
热议问题