查找文件并打印完整路径

Find file and print complete path

我的项目文件夹结构如下:

tests
  - features
  - payloads
     - request
        -JSONRequest (create-req.json file is present inside this folder)
        -XMLRequest (sample-req.xml file is present inside this folder)

我必须根据找到的 create-req.json 文件打印完整的 PATH

我创建了一个名为 requestDataPath 的变量,它存储了 'request' 结构的路径。我根据作为参数传递的值选择 json 请求。我正在尝试根据文件所在的文件夹打印完整路径。

let path = require('path');
let requestDataPath = path.resolve('tests/payloads/request/../');

let requestBodyPath = requestDataPath + '/' + 'create' + '-req.json';

console.log('Path is-->' + requestBody);

实际结果:/Users/pranaytgupta/Documents/pranay/api-automation-framework/tests/payloads/request/create-req.json

预期结果:/Users/pranaytgupta/Documents/pranay/api-automation-framework/tests/payloads/request/JSONRequest/create-req.json

如果您是 运行 来自主目录的,请尝试:

  const path = `${__dirname}/tests/payloads/request/JSONRequest/create-req.json`
  console.log('path is -->', path);