Batch Processing error

Hello everyone, I am applying mrthreshold to obtain a binary image from a density image. I want to perform this processing for each of the subfolders I have.

The folders are organized as follows:

TractSeg_64_atlas/AF_left/AF_left_sum.nii.gz
TractSeg_64_atlas/AF_right/AF_right_sum.nii.gz
TractSeg_64_atlas/ATR_left/ATR_left_sum.nii.gz

I want the binary image to be saved with the same name as the folder + _50.nii.gz, that is, AF_left_50.nii.gz. To do this, I am using the for_each command, which worked correctly but had some issues for certain folders.

for_each TractSeg_64_atlas/* : mrthreshold IN/PRE_sum.nii.gz -abs 32 IN/PRE_50.nii.gz