You can use
texosquery to obtain file listings. It's a Java application designed to be used within TeX's shell escape using the interface provided by
texosquery.sty is just a small wrapper package that inputs the generic TeX code.)
If you want to use it with TeX's restricted mode, you need to set up the
texosquery.cfg file to allow it. However, the restricted mode forbids certain characters to prevent malicious code injection, so it probably won't work in restricted mode with path names that contain spaces. If you have spaces, as your question seems to suggest, then you'll need the less secure unrestricted mode.
You can find all sub-directories using
\TeXOSQuerySubDirList. For example:
This example just lists the sub-directory names in the current directory (
.), which are fetched and stored in a comma-separated list (
This doesn't descend the subdirectories and just has the base name (not the full path) for each element of the list. If you want an alphabetically ordered list you can use
Another possibility is to hierarchically search for all files that match a particular regular expression. For example
.+\.tex to match all files with the
In this case, each element of the list is a relative path. Since it's designed to work within TeX,
/ is used as the directory separator.