1

I have a bunch of rasters with different file formats in a folder (most of them are GRID). Using describe of arcpy, I want my script to inform the following: when all rasters have the same format, inform once the file format e.g print "All the rasters has the XXX format", but when there are different formats, list the formats of each raster. I'm very new to scripting so by now the code I wrote print all the files with their format.

How can I do that?

The code block is:

for dpath, dnames, fnames in os.walk(lu_folder):
    arcpy.env.workspace = dpath
    print "\nThe format of LU rasters are:"
    for raster in arcpy.ListRasters('*'):
        desc = arcpy.Describe(raster)
        print  "{0}: {1}".format(raster, desc.format)

1 Answer 1

0

This will give you a list with unique file formats:

import arcpy
import os

lu_folder = r"G:\testing_del\rasters"

for dpath, dnames, fnames in os.walk(lu_folder):
    arcpy.env.workspace = dpath
    some_list = []
    for raster in arcpy.ListRasters('*'):
        desc = arcpy.Describe(raster)
        some_list.append(desc.format)
    unique_items_list = list(set(some_list))
    print unique_items_list
2
  • Great! It's already much better! Now I just have to print a full list when I have more than one extension ...looking for it. Thanks a lot!
    – renan-brso
    Commented Nov 6, 2018 at 12:00
  • @rber If this answer resolves your problem - please press the "Accept" button. Commented Nov 6, 2018 at 12:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.