I feel like I am forgetting something obvious, and will remember or be ashamed as soon as an answer turns up. However, I cannot for the life of me get all of the directories in the current working directory. That is, given the following folder structure:
a
-c
b
-c
I would expect
FileNames["*",{"*"},Infinity]
to return
{"a","b","a/c","b/c"}
But instead I get
{"a/c","b/c"}
I tried playing around with Infinity
in the typical Level
s in Mathematica (such as {1} vs. 1), but MMA complains about syntax. For the above example, how can I view a complete list of subdirectories. I came up with the following, but it doesn't seem exactly elegant:
RecursiveDirectory[dir_] :=
Module[{allDirs, allDirsCheck = {}, tempDirs},
allDirs = Select[FileNames["*"], DirectoryQ[#] &];
While[allDirs != allDirsCheck,
allDirsCheck = allDirs;
tempDirs = Select[FileNames["*", allDirs], DirectoryQ[#] &];
allDirs = Union[allDirs, tempDirs]
];
allDirs
]
This function gives me:
In[30]:= RecursiveDirectory["*"]
Out[30]= {"a", "a\\c", "b", "b\\c"}
As expected. What is a nicer way of doing this?