[CMake] Retrieve all directories?

David Cole david.cole at kitware.com
Mon Jan 15 11:35:18 EST 2007


Sorry for the very delayed response, but... the following CMake code
correctly identifies directories for me on Windows with CMake 2.4:
PROJECT(DetectDirectories)

FILE(GLOB fl "*")

FOREACH(f ${fl})
  IF(EXISTS "${f}/")
    MESSAGE(STATUS "  directory: '${f}'")
  ELSE(EXISTS "${f}/")
    MESSAGE(STATUS "       file: '${f}'")
  ENDIF(EXISTS "${f}/")
ENDFOREACH(f)

It exploits the fact that a directory will still pass the existence test if
you append a "/" to its filename, whereas a file will not...

I won't guarantee that this will always work with all cmakes on all
platforms, but you may find that it is a useful trick...

:-),
David

On 11/22/06, Timo Rumland <cr at olympclan.de> wrote:
>
> Hello,
>
> is it in any way possible to retrieve the list of directories within a
> given directory and store it into a variable?
>
> I'm looking for something like FILE(GLOB ... ) or
> FILE(GLOB_RECURSE...) that collects directory names instead of files.
>
>
> Thanks in advance
>
>
> Timo
>
> _______________________________________________
> CMake mailing list
> CMake at cmake.org
> http://www.cmake.org/mailman/listinfo/cmake
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://public.kitware.com/pipermail/cmake/attachments/20070115/a614356a/attachment.htm


More information about the CMake mailing list