Skip to content
Advertisement

how do you create a directory that has 3 other directorys in it and so on

Im trying to create a sort of maze of directorys in java. one directory should have 3 other of it within it and those should also have 3 directory in them up until a certain “deepness level” is reached. I tried something but i couldn’t get it to work properly, it does create 3 folders in one but not inside of the other folders.

my java code:

JavaScript

I have a bit of trouble expressing myself if i forgot to mention something important please remind me and i will add it.

Advertisement

Answer

if you reach the maximum level return to stop the recursion:

JavaScript

else create a folder. The folder name is the level + index instead of a random name from a list to avoid overwrites due to the same folder name:

JavaScript

and finally call createFolders recursively:

JavaScript

Complete code:

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement