0

I am trying to convert my TIFF files into ASCII files. I have a code written out that is doing exactly what I need done BUT when it converts it to an ASC file, it puts ".tif" on the end of the original file name - which I can't have.

import os
dir_name = 'C:\\PRCPRaster'
for filename in os.listdir(dir_name):
    if not filename.endswith(".tif"): continue
    full_path = os.path.join(dir_name, filename)
    outASCII = '%s.asc' % (full_path)
    arcpy.conversion.RasterToASCII(full_path, outASCII)

I have tried to debug my current code but haven't had any such luck. I'm sure its a simple fix but I'm still pretty new to python and would love some assistance if anyone has an easy fix for me!

Compo
  • 36,585
  • 5
  • 27
  • 39
kdsieg15
  • 13
  • 2
  • You check that finename ends with .tif, then construct full_path with that filename that ends with .tif. Remove .tif first. – Mark Tolonen Nov 06 '22 at 22:25
  • @MarkTolonen I'm sorry I'm not quite sure if I understand correctly, would you be willing to help me though? – kdsieg15 Nov 08 '22 at 18:28
  • The [duplicate](https://stackoverflow.com/questions/2900035/changing-file-extension-in-python) has multiple examples – Mark Tolonen Nov 08 '22 at 19:51

0 Answers0