Include subdirectories and exclude their content with fileTree

├── file1.txt
├── folder1
|  └── anotherfile.txt
├── folder2
|  └── subsubfolder
└── folderN

When I do

println fileTree("d:\build").collect()

I get

[d:\build\file1.txt, d:\build\folder1\anotherfile.txt]

What I want is

[d:\build\file1.txt, d:\build\folder1, d:\build\folder2, d:\build\folderN]

The reason I want to use fileTree with .collect() is because it’s lazy[0] and does not give null pointer exception[1] at configuration stage.

How do I do that?

[1] Pass a directory which is not created yet in configuration step