How to gather output files from subdirectories

Hello,
I have a tool that downloads a database with image files saved in subdirectories within the output folder. I’m writing a CWL for this tool to gather the files from these subdirectories, but it fails because inputs.outDir.listing is empty. It seems that loadContents doesn’t work for arrays.
I appreciate your help!

class: CommandLineTool
cwlVersion: v1.2
inputs:
  name:
    inputBinding:
      prefix: --name
    type: string
  outDir:
    inputBinding:
      prefix: --outDir
    type: Directory

  glob_pattern:
    type: string
    default: "."

outputs:
  outDir:
    outputBinding:
      glob: $(inputs.outDir.basename) #"$(inputs.inputDir)/**/*.tif"
    type: Directory

  output_files:
    type: File[]
    outputBinding:
      glob: $(inputs.outDir.basename)/* 
      loadContents: true
      outputEval: |
        ${
          var tifFiles = [];
          
          function findTifFiles(dir) {
            for (var item of dir.listing) {
              if (item.class == 'Directory') {
                findTifFiles(item); // Recursively search subdirectories
              } else if (item.class == 'File' && item.basename.endsWith('.tif')) {
                tifFiles.push({ "class": "File", "path": item.path });
              }
            }
          }
          
          findTifFiles(inputs.outDir); // Start the recursive search in outDir
          return tifFiles;
        }      
baseCommand: ["python3", "-m", "polus.plugins.utils.bbbc_download"]
requirements:
  DockerRequirement:
    dockerPull: polusai/bbbc-download-plugin:0.1.0-dev1
  InitialWorkDirRequirement:
    listing:
    - entry: $(inputs.outDir)
      writable: true
  InlineJavascriptRequirement: {}
  NetworkAccess:
    networkAccess: true

Welcome @ndonyapour , and thank you for your question.

Instead of asking for the output directory as one of the inputs, I suggest removing that and manually specifying the current working directory with . or $(runtime.outdir)

class: CommandLineTool
cwlVersion: v1.2
inputs:
  name:
    inputBinding:
      prefix: --name
    type: string

arguments:
 - --outDir
 - $(runtime.outdir)

outputs:
  outDir:
    type: Directory
    outputBinding:
      glob: $(runtime.outdir)
    loadListing: deep_listing

  output_files:
    type: File[]
    outputBinding:
      outputEval: |
        ${
          var tifFiles = [];
          
          function findTifFiles(dir) {
            for (var item of dir.listing) {
              if (item.class == 'Directory') {
                findTifFiles(item); // Recursively search subdirectories
              } else if (item.class == 'File' && item.basename.endsWith('.tif')) {
                tifFiles.push({ "class": "File", "path": item.path });
              }
            }
          }
          
          findTifFiles(inputs.outDir);
          return tifFiles;
        }      
baseCommand: ["python3", "-m", "polus.plugins.utils.bbbc_download"]
hints:
  DockerRequirement:
    dockerPull: polusai/bbbc-download-plugin:0.1.0-dev1
requirements:
  InlineJavascriptRequirement: {}
  NetworkAccess:
    networkAccess: true