Go to the back folder

Hi,

Im trying to go to the back folder but i didnt find the way to do

Example, i have "D:\MA.ING\NODE\TEST\2024" and i want to go one folder back to: "D:\MA.ING\NODE\TEST"

I tryed spliting and rejoining but nothing worked for me, someone know what can i do?

Thank you in advanced.
Regards.

A little more information would be useful. Are you using a file node? (which one) an exec node?

Put together a small example flow demonstrating the issue and then export it and paste it to a reply.
Also what version of Node-RED and node.js are you using? (you can get these from th startup log)

If you just want to convert the string "D:\MA.ING\NODE\TEST\2024" to "D:\MA.ING\NODE\TEST", this little flow will do it.
I'm absolutely certain it can be done with fewer steps, this is just an example.

An OS agnostic way is using path.join in a function.

const startPath = 'D:/MA.ING/NODE/TEST/2024'
const up1 = path.join(startPath, '..')

// alternatively use double backslashes:
// const startPath = 'D:\\MA.ING\\NODE\\TEST\\2024'

proof on linux
image

proof on windows:
image

NOTE: you might need to add path to the function setup tab

It may be easier if you use forward slashes rather than backslashes, as backslashes can have a special meaning in strings. Windows works perfectly well with forward slashes.

[Edit] that was supposed to be a reply to the original post.

Thank you so much for all the answers.

Steve-Mcl this works so fine, i tryed similar but no with '..'

One more question, its possible to limit this back, for example, only can go back until D:/MA.ING? es decir, no permitir llegar a D:/

Thanks!

check out this flow that does just that.

https://flows.nodered.org/flow/db68bd4934cf46f39e6e453a348bc419

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.