本文介绍了使用__dirname时,如何去父目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
目录结构
- WebApiRole
- gulpFile.js
- Karma.conf.js
来自 GulpFile.js
gulp.task('test', function (done) { karma.start({ configFile: _configFile: __dirname + '\\..\\test\\karma.conf.js', singleRun: true }, done); });
所以我的问题去父目录并访问 karma.conf.js 。由于某些原因,路径不能通过
.. \\
解决,以返回到WebApiRole的父目录。有人可以指向正确的方向吗?So my problem going to the parent directory and access the karma.conf.js . For some reason the path is not get resolved with
..\\
to go back to the parent directory of WebApiRole . can someone point me in the right direction ?推荐答案
我不得不使用
路径
package来解决这个问题。I had to use
path
package to resolve this issue .var path = require("path"), fs = require("fs"); gulp.task('test', function (done) { karma.start({ configFile: fs.readFile(path.join(__dirname, '../test/', 'karma.conf.js')), singleRun: true }, done); });
这篇关于使用__dirname时,如何去父目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!