Home > Mobile >  How to include first-degree directory but exclude second-degree directory?
How to include first-degree directory but exclude second-degree directory?

Time:05-23

My directory structures are like below

/image03

 /UM1234ABCD2R1_MRI
   /UM1234ABCD2R1

 /UM1234ABCD1R1_MRI
   /UM1234ABCD1R1

 /UM0120AABD1R1_DTI
   /UM0120AABD1R1

 /UM0120AABC1R1_bold_reward
   /UM0120AABC1R1

 /CU0112XCMF2R1_b0map_bold
   /CU0112XCMF2R1

 /CU1243XMDM1R1_b0map_dti
   /CU0112XCMF2R1

and I want to do some jobs using the command below

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

for this, I wanted to include only first degree of directory but it includes second degree directories... like below

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

how to I fix this?

)) I want actually run dcm2bids -d %s -p %s -s %s -c ./dcm2bids_config.json;, how to erase printf in above code?

CodePudding user response:

To exclude nested subdirectories, you can use -maxdepth.

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

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

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

You can also use -mindepth to exclude the working directory:

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