[英]How extract file names in nodejs?
I have a project, that responds with items that user searches.我有一个项目,它响应用户搜索的项目。 Each item has its type and meta number (404-0. 404 for type, 0 for meta).
每个项目都有其类型和元编号(404-0。404 表示类型,0 表示元)。 Also I have a folder with item images, image name corresponds to the type and meta number of the item.
另外我有一个包含项目图像的文件夹,图像名称对应于项目的类型和元编号。 How can I get through all image folder and extract only its name (404-0 without .img) ?
如何浏览所有图像文件夹并仅提取其名称(404-0 不带 .img)?
[
{
"type": 0,
"meta": 0,
"name": "Air",
"text_type": "air"
},
{
"type": 1,
"meta": 0,
"name": "Stone",
"text_type": "stone"
},
{
"type": 1,
"meta": 1,
"name": "Granite",
"text_type": "stone"
},
{
"type": 1,
"meta": 2,
"name": "Polished Granite",
"text_type": "stone"
},
{
"type": 1,
"meta": 3,
"name": "Diorite",
"text_type": "stone"
},
{
"type": 1,
"meta": 4,
"name": "Polished Diorite",
"text_type": "stone"
}
]
Have you tried?你有没有尝试过?
const files = fs.readdirSync('path/to/folder').map(name => name.split('.')[0])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.