如何包含一级目录但排除二级目录?

How to include first-degree directory but exclude second-degree directory?

我的目录结构如下

/image03

 /UM1234ABCD2R1_MRI
   /UM1234ABCD2R1

 /UM1234ABCD1R1_MRI
   /UM1234ABCD1R1

 /UM0120AABD1R1_DTI
   /UM0120AABD1R1

 /UM0120AABC1R1_bold_reward
   /UM0120AABC1R1

 /CU0112XCMF2R1_b0map_bold
   /CU0112XCMF2R1

 /CU1243XMDM1R1_b0map_dti
   /CU0112XCMF2R1

我想使用下面的命令做一些工作

find . -type d -not -name "*b0map*" | awk '{printf("dcm2bids -d %s -p %s -s %s -c ./dcm2bids_config.json;\n", [=11=], substr([=11=],3,6), substr([=11=],13,1));}'

为此,我只想包含一级目录,但它包含二级目录...如下所示

dcm2bids -d .//CU1243XMDM1R1_b0map_dti/CU0112XCMF2R1 -p CU1243 -s 1 -c ./dcm2bids_config.json;

我该如何解决这个问题?

+)) 我实际上想要 运行 dcm2bids -d %s -p %s -s %s -c ./dcm2bids_config.json;,如何删除上面代码中的 printf

要排除嵌套子目录,可以使用-maxdepth.

> tree
.
├── foo1
│   └── bar2
└── spam1
    └── eggs2

> find . -type d
.
./spam1
./spam1/eggs2
./foo1
./foo1/bar2

> find . -maxdepth 1 -type d
.
./spam1
./foo1

您也可以使用-mindepth排除工作目录:

> find . -maxdepth 1 -mindepth 1 -type d
./spam1
./foo1