Skip to content

Commit 3afea0c

Browse files
committed
enh: selectdirs too
1 parent 5715005 commit 3afea0c

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

nipype/interfaces/io.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1186,17 +1186,19 @@ def _list_outputs(self):
11861186
class SelectFilesInputSpec(DynamicTraitedSpec, BaseInterfaceInputSpec):
11871187

11881188
base_directory = Directory(exists=True,
1189-
desc="Root path common to templates.")
1189+
desc="Root path common to templates.")
11901190
sort_filelist = traits.Bool(True, usedefault=True,
1191-
desc="When matching mutliple files, return them in sorted order.")
1191+
desc="When matching mutliple files, return them in sorted order.")
11921192
raise_on_empty = traits.Bool(True, usedefault=True,
1193-
desc="Raise an exception if a template pattern matches no files.")
1193+
desc="Raise an exception if a template pattern matches no files.")
11941194
force_lists = traits.Either(traits.Bool(), traits.List(Str()),
1195-
default=False, usedefault=True,
1196-
desc=("Whether to return outputs as a list even when only one file "
1197-
"matches the template. Either a boolean that applies to all "
1198-
"output fields or a list of output field names to coerce to "
1199-
" a list"))
1195+
default=False, usedefault=True,
1196+
desc=("Whether to return outputs as a list even when only one file "
1197+
"matches the template. Either a boolean that applies to all "
1198+
"output fields or a list of output field names to coerce to "
1199+
" a list"))
1200+
directory_mode = traits.Bool(False, usedefault=True,
1201+
desc="Return only directories.")
12001202

12011203

12021204
class SelectFiles(IOBase):
@@ -1303,6 +1305,10 @@ def _list_outputs(self):
13031305
else:
13041306
template = op.abspath(template)
13051307

1308+
if self.inputs.directory_mode:
1309+
# return only directories
1310+
template += os.sep
1311+
13061312
# Fill in the template and glob for files
13071313
filled_template = template.format(**info)
13081314
filelist = glob.glob(filled_template)

nipype/interfaces/tests/test_auto_SelectFiles.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
def test_SelectFiles_inputs():
77
input_map = dict(base_directory=dict(),
8+
directory_mode=dict(usedefault=True,
9+
),
810
force_lists=dict(usedefault=True,
911
),
1012
ignore_exception=dict(nohash=True,

0 commit comments

Comments
 (0)