AnsweredAssumed Answered

Replace file names in a folder

Question asked by drycreekeng on Jun 25, 2019
Latest reply on Jun 25, 2019 by Dan_Patterson
import arcpy
import os

arcpy.env.workspace = r"C:\Users\natb0\OneDrive - drycreekeng.com\GIS\GIS\Data\Dry_Creek\TerrAvion_Imagery\062319"
input_folder = arcpy.env.workspace

for p in os.listdir(input_folder):
    p.replace("CIR_4326", "RGB_062319")
    p.replace("TIRS_T_4326", "Temp_062319")
    p.replace("NDVI_NDVI_2_4326", "NDVI_062319")
    print p

I have to download 48 images from a website weekly, and I would like to write a script to rename the files to something more user friendly and understandable.  For each farm field (16 fields total), I download 3 images (#farmfield_TIRS_T_4326.tiff, #farmfield_CIR_4326.tiff, and #farmfield_NDVI_NDVI_2_4326.tiff), where TIRS = temperature, CIR = infrared, and NDVI is NDVI. For each file name, I would like to replace "TIRS_T_4326" with "Temp_062319",  "CIR_4326" with "RGB_062319", and "NDVI_NDVI_2_4326" with "NDVI_062319".  When I run the code, it runs fine but the file names do not change.  So Im guessing .replace is the wrong argument.  Does anyone know what I should use instead? My goal is to do a find a replace on the file names. 

Outcomes