Can the RecoverCompressedFile Tool restore several compressed images from a directory?

I need to restore serveral thousand compressed files to their original *.dcm format that reside in serveral different directories. I have tried using the RecoverCompressedFile Maintenance Tool which only completes the process if I specify each file by name one at a time. So I used the following script below to run the RecoverCompressedFile on each compressed file while descending through directories.

#!/bin/bash
# UnCompressedDir.sh

shopt -s globstar
for file in /home/Programs/orthanc/OrthancStorage/* OrthancStorage/**/*
do
   /home/Programs/orthanc/Resources/Samples/Tools/RecoverCompressedFile "$file" /home/UncompressedDICOM/"$file" ;

done

This returns the Errors below. Is there a way to decompress multiple files in a directory sucessfully to their orignal DICOM state? Also I am migrating to a new PACS DICOM so I can't use the Replicate option. I tried the Direct Acces Method as well however that process is ingorning several of the images in OrthancStorage.

Reading the file into memory...
terminate called after throwing an instance of 'std::length_error'
  what(): basic_string::resize
./UncompressDir.sh: line 4: 23962 Aborted (core dumped) /home/Programs/orthanc/Resources/Samples/Tools/RecoverCompressedFile "$file" /home/Programs/orthanc/OrthancStorage/"$file"
Reading the file into memory...
Decompressing the content of the file...
Error: Zlib: Corrupted compressed buffer
Reading the file into memory...
Decompressing the content of the file...
Error: Zlib: Corrupted compressed buffer
Reading the file into memory...
Decompressing the content of the file...
Error: Zlib: Corrupted or incomplete compressed buffer
Reading the file into memory...
Decompressing the content of the file...
Writing the uncompressed data...
Error: Cannot write to file

Ok no longer getting the buffering Errors however the script is not writing to the new location after decompression. I have given full write permissions to the directory. Any ideas? see script below.

#!/bin/bash

# Intialize Array, Find file names then put them into the Array

names=( $(find /home/Programs/testdev/OrthStorage -type f ) )

# Initialize counter

counter=0

# Print the count and filenames from the Array, Run the (RecoverCompressedFile) program, Pause for 1/20 of second, Loop it over

for dicom in "${names[@]}";

do let counter++; echo "Executing $dicom on file number $counter"; /home/Programs/orthanc/Resources/Samples/Tools/RecoverCompressedFile "$dicom" /home/Programs/testdev/NewStorage/"$dicom" ; sleep .2;
    
done

Hello,

IMHO, this looks like a problem with bash, not with Orthanc.

Please explain your question on StackOverflow, which is a better way of discussing bash-related issues:
http://stackoverflow.com/

Regards,
Sébastien-

Since my last post I finally determined what was happening with the buffering issue but didn't post the resolution. Of course as you mentioned it was bash related below is a script that automates the process. I'm sure it can be improved but it works. Thanks.

Since my last post I finally determined what was happening with the buffering issue but didn’t post the resolution. Of course as you mentioned it was bash related below is a script that automates the process. I’m sure it can be improved but it works. Thanks.

Thanks for sharing!

Sébastien-