#@ File (label = "Input directory", style = "directory") src_dir

import os

from ij import IJ
from loci.formats import ImageReader

filepaths = []
for root, dirnames, filenames in os.walk(src_dir.getAbsolutePath()):
    for filename in filenames:
        if filename.endswith('.czi'):
            filepaths += [os.path.join(root, filename)]

for filepath in filepaths:
    reader = ImageReader()
    reader.setId(filepath)
    seriesCount = reader.getSeriesCount()

    if seriesCount == 1:
        output_paths = [os.path.splitext(filepath)[0] + ".tif"]
    else:
        output_paths = [os.path.splitext(filepath)[0] + "_" + str(i+1) + ".tif" for i in range(seriesCount)]

    for i, output_path in enumerate(output_paths):
        IJ.run("Bio-Formats", "open=["+filepath+"] autoscale view=Hyperstack series_" + str(i+1))
        imp = IJ.getImage()
        imp.hide()
        imp.setDisplayMode(IJ.COMPOSITE)
        IJ.saveAs(imp, "TIFF", output_path)
        imp.close()