Wednesday, 17 May 2017

Moving to previous directory given full path name

Say we have a path, C:/Users/me/projects. I would like to, from that path, be able to navigate through the directories. For example I can do:

//Current directory, C:/Users/me/projects

const something = require('../file.js');

Which would point to the file file.js in the directory right behind. However, I would like to be able to go backwards just like that but given a full path, something like

console.log(__dirname + '/../')

Which would go backwards from the current directory. But of course, it doesn't work like that. It would just be C:/Users/me/projects/../.



via Wright

No comments:

Post a Comment