Repository: nipy/nipype

Issue:
How to use SelectFiles to read all directories inside a folder? 
Here is my data_organization function. This is used in the first node of my workflow. 
```
def data_organization(in_path):
    do_something...
    return out_path
```
The function receives `in_path` as an input (a directory) which is a path of one subject folder. Then it organizes all the sub-folders in a desired way and it returns the path of the organized folder. Folders' name have a pattern. As `SelectFiles` finds **files** with specific patterns, is it possible to use it to find specific **directories** and pass them other nodes (e.g. to the above node)?


Discussion:

Resolving patch:
diff --git a/nipype/interfaces/io.py b/nipype/interfaces/io.py
--- a/nipype/interfaces/io.py
+++ b/nipype/interfaces/io.py
@@ -1188,15 +1188,18 @@ class SelectFilesInputSpec(DynamicTraitedSpec, BaseInterfaceInputSpec):
     base_directory = Directory(exists=True,
                                desc="Root path common to templates.")
     sort_filelist = traits.Bool(True, usedefault=True,
-                                desc="When matching mutliple files, return them in sorted order.")
+                                desc="When matching mutliple files, return them"
+                                " in sorted order.")
     raise_on_empty = traits.Bool(True, usedefault=True,
-                                 desc="Raise an exception if a template pattern matches no files.")
+                                desc="Raise an exception if a template pattern "
+                                "matches no files.")
     force_lists = traits.Either(traits.Bool(), traits.List(Str()),
                                 default=False, usedefault=True,
-                                desc=("Whether to return outputs as a list even when only one file "
-                                      "matches the template. Either a boolean that applies to all "
-                                      "output fields or a list of output field names to coerce to "
-                                      " a list"))
+                                desc=("Whether to return outputs as a list even"
+                                " when only one file matches the template. "
+                                "Either a boolean that applies to all output "
+                                "fields or a list of output field names to "
+                                "coerce to a list"))
 
 
 class SelectFiles(IOBase):
@@ -1296,6 +1299,8 @@ def _list_outputs(self):
 
         for field, template in list(self._templates.items()):
 
+            find_dirs = template[-1] == os.sep
+
             # Build the full template path
             if isdefined(self.inputs.base_directory):
                 template = op.abspath(op.join(
@@ -1303,6 +1308,10 @@ def _list_outputs(self):
             else:
                 template = op.abspath(template)
 
+            # re-add separator if searching exclusively for directories
+            if find_dirs:
+                template += os.sep
+
             # Fill in the template and glob for files
             filled_template = template.format(**info)
             filelist = glob.glob(filled_template)


Test patch: