在我的文件系统中,我的工作目录在这里:
C:\temp\a\b\c\d
而在b\bb下有一个名为tmp.txt的文件:
C:\temp\a\b\bb\tmp.txt
如果我想从我的工作目录进入此文件,我将使用以下路径:
"../../bb/tmp.txt"
如果文件不存在,我想记录完整路径并告诉用户:
"文件C:\temp\a\b\bb\tmp.txt不存在"。
我的问题:
我需要一些函数,将相对路径: "../../bb/tmp.txt" 转换为绝对路径:"C:\temp\a\b\bb\tmp.txt"
在我的代码中应该是这样的:
console.log("The file" + convertToAbs("../../bb/tmp.txt") + " is not exist")
const {resolve} = require("path");
。 - harveyhansesm
,可以这样写:import path from 'path'
,然后调用path.resolve()
。 - Timo