I am trying to achieve this

Write a script (in any language) that accepts a single parameter (depth) to create the expected folders and files:

1. At depth 0, create a folder named 0, and create a file in it with its relative path as the content.
2. At depth 1: besides what should be done with depth 0, create two subfolders named 0 and 1 and create a file to save its path in both respectively.
3. At depth 2: besides what should be done at depth 1, create subfolders in folders created at depth 1, and name them as 0, 1 and 2, and create files following the same rule.
4. At depth N: Same rules.

---

I tried this way,

```
const fs = require('fs');

function makedir(depth) {
    let newpath = [];
    for (let i = 0; i <= depth; i++) {
        newpath.push(i);
        let joined = newpath.join('/');
        if (!fs.existsSync(joined)) {
            fs.mkdirSync(joined);
            fs.writeFileSync('path.txt', joined);
        }
    }
}
makedir(2);

```

But it failed to do the job.  

It only created folders like this 0/1/2 and a file only in the root directory