Skip to content

Commit a40e056

Browse files
authored
Merge pull request #2134 from mgxd/enh/selectdirs
enh: selectfiles select(only)dirs too
2 parents 1a74013 + 06b45ee commit a40e056

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

nipype/interfaces/io.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1188,15 +1188,18 @@ class SelectFilesInputSpec(DynamicTraitedSpec, BaseInterfaceInputSpec):
11881188
base_directory = Directory(exists=True,
11891189
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"
1192+
" in sorted order.")
11921193
raise_on_empty = traits.Bool(True, usedefault=True,
1193-
desc="Raise an exception if a template pattern matches no files.")
1194+
desc="Raise an exception if a template pattern "
1195+
"matches no files.")
11941196
force_lists = traits.Either(traits.Bool(), traits.List(Str()),
11951197
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"))
1198+
desc=("Whether to return outputs as a list even"
1199+
" when only one file matches the template. "
1200+
"Either a boolean that applies to all output "
1201+
"fields or a list of output field names to "
1202+
"coerce to a list"))
12001203

12011204

12021205
class SelectFiles(IOBase):
@@ -1296,13 +1299,19 @@ def _list_outputs(self):
12961299

12971300
for field, template in list(self._templates.items()):
12981301

1302+
find_dirs = template[-1] == os.sep
1303+
12991304
# Build the full template path
13001305
if isdefined(self.inputs.base_directory):
13011306
template = op.abspath(op.join(
13021307
self.inputs.base_directory, template))
13031308
else:
13041309
template = op.abspath(template)
13051310

1311+
# re-add separator if searching exclusively for directories
1312+
if find_dirs:
1313+
template += os.sep
1314+
13061315
# Fill in the template and glob for files
13071316
filled_template = template.format(**info)
13081317
filelist = glob.glob(filled_template)

0 commit comments

Comments
 (0)