I used the following code to access a file in my project. It worked great when the code file was located in the root folder. However, I've moved the file into the folder ( utils ) and now it's getting the wrong path.
var filePath = path.join(__dirname, '/test/test.txt'
);
Currently I'm getting
c://Users//i0433//WebstormProjects//Aps//utils//test//test.txt'
I need to remove utils so I can get the correct path.
c://Users//i0433//WebstormProjects//Aps//test//test.txt'
通常在这种情况下,在路径的开头添加..
即可:
var filePath = path.join(__dirname, '../test/test.txt');
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.