Search code examples
pythongdalhdf

Adding a count to a list of files whilst processing


Very new to python,

Trying to bulk process a number of .hdf files,

The problem is the process I'm trying to do won't allow me to add an integer and a string together in the re-naming process.

    # Import Modules

import subprocess
import glob

ProcessList = glob.glob('*.hdf')

# Extract sub-datasets

Count = 1

for MODfile in ProcessList:


    Outfile = MODfile.replace('.hdf', Count + '_Processed.hdf')

    subprocess.call('gdal_translate -of GTIFF -sds ' + MODfile + ' ' + Outfile, shell=True)

    Count = (Count + 1)

print("Extracted subdatasets")

Thanks


Solution

  • Try to convert int to string

    Outfile = MODfile.replace('.hdf', str(Count) + '_Processed.hdf')