java - Recursively create directory -
does know how use java create sub-directories based on alphabets (a-z) n levels deep?
/a /a /a /b /c .. /b /a /b .. .. /a /b /c .. /b /a /a /b .. /b /a /b .. .. /a /b .. .. /a /a /b .. /b /a /b .. .. /a /b ..
public static void main(string[] args) { file root = new file("c:\\so"); list<string> alphabet = new arraylist<string>(); (int = 0; < 26; i++) { alphabet.add(string.valueof((char)('a' + i))); } final int depth = 3; mkdirs(root, alphabet, depth); } public static void mkdirs(file root, list<string> dirs, int depth) { if (depth == 0) return; (string s : dirs) { file subdir = new file(root, s); subdir.mkdir(); mkdirs(subdir, dirs, depth - 1); } }
mkdirs
recusively creates depth
-level directory tree based on given list of string
s, which, in case of main
, consists of list of characters in english alphabet.
Comments
Post a Comment