本文介绍了nodejs从绝对路径获取文件名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否有任何API可以从绝对文件路径中检索文件名?
If there any API could retrieve file name from an absolute file path?
例如来自"/var/www/foo.txt"
我知道它可用于字符串操作,例如fullpath.replace(/.+\//, '')
但是我想知道还有没有一种更正式"的方式,就像Java中的file.getName()
一样.
I know it works with string operation, like fullpath.replace(/.+\//, '')
but I want to know is there a more 'formal' way, like file.getName()
in java, could do it.
NodeJS是否从绝对路径获取文件名?
NodeJS get file name from absolute path?
推荐答案
使用path
模块的basename
方法:
path.basename('/foo/bar/baz/asdf/quux.html')
// returns
'quux.html'
此处是上面示例的文档.
这篇关于nodejs从绝对路径获取文件名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!