Wednesday, 12 April 2017

Convert file path to nested array

I am trying to use JavaScript (Node) to convert a file path into a multidimensional array.

Basically, i want

/test/hello/folder/file.txt

to turn into

{
  test: {
    hello: {
      folder: {
        'file.txt'
      }
    }
  }
}

A bit stuck, lots of Googling without luck, a bit unsure what to Google. Any ideas how to solve this?



via Freddy

No comments:

Post a Comment