Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wildcard to obtain list of all directories

In my Makefile I need to get a list of all directories present in some other directory.

To get a list of all directories in the same folder as my Makefile I use:

DIRECTORIES = $(wildcard */)  all:     echo $(DIRECTORIES) 

which works fine, and gives me the desired list. However if I want to have a list of all directories in another directory using

DIRECTORIES = $(wildcard ../Test/*/)  all:     echo $(DIRECTORIES) 

I get a list of ALL files (with paths) in that directory, including .h and .cpp files.

Any suggestions why this happens and how to fix it? Other solutions to obtain the list are also welcome.

like image 287
Haatschii Avatar asked Dec 16 '12 01:12

Haatschii


People also ask

How do I get a list of all folders and subfolders?

Substitute dir /A:D. /B /S > FolderList. txt to produce a list of all folders and all subfolders of the directory. WARNING: This can take a while if you have a large directory.

How do you use wildcards to search files and folders?

You can use your own wildcards to limit search results. You can use a question mark (?) as a wildcard for a single character and an asterisk (*) as a wildcard for any number of characters. For example, *. pdf would return only files with the PDF extension.

How do I get a list of directories in R?

The list. dirs() method in R language is used to retrieve a list of directories present within the path specified. The output returned is in the form of a character vector containing the names of the files contained in the specified directory path, or returns null if no directories were returned.


1 Answers

Use sort and dir functions together with wildcard:

DIRECTORY = $(sort $(dir $(wildcard ../Test/*/))) 

From GNU make manual:

$(dir names...) Extracts the directory-part of each file name in names. The directory-part of the file name is everything up through (and including) the last slash in it. If the file name contains no slash, the directory part is the string ‘./’.

$(sort list) Sorts the words of list in lexical order, removing duplicate words. The output is a list of words separated by single spaces.

Also look at the second and the third method in this article: Automatically Creating a List of Directories

like image 173
Lei Mou Avatar answered Oct 11 '22 14:10

Lei Mou