如何使用JavaScript从完整路径获取文件名? [英] How to get the file name from a full path using JavaScript?

查看:113
本文介绍了如何使用JavaScript从完整路径获取文件名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法可以从完整路径获取最后一个值(基于'\'符号)?

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

示例:

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

在这种情况下,我只想从JavaScript的完整路径获取 recycle log.jpg

With this case, I just want to get recycled log.jpg from the full path in JavaScript.

推荐答案

var filename = fullPath.replace(/^.*[\\\/]/, '')

这将处理\ OR / in path

This will handle both \ OR / in paths

这篇关于如何使用JavaScript从完整路径获取文件名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆