Select to view content in your preferred language

Name output using input base name (minus extension)

1689
10
08-15-2011 09:28 AM
deleted-user-XuRyPg9pv1OY
Deactivated User
Hi All,

In modelbuilder, I need to use the base name from an input file to name an output later in the process.  For example, I have NetCDF files named like A12_G01_X00_ABCABC10.nc.  I want to clip the features and name the output using the same name, minus the ".nc" extension.

I can easily use the input filename as an inline variable using %InputFile%.shp, but that produces A12_G01_X00_ABCABC10.nc.shp, which contains an extra period and therefore creates an illegal character.

Is it possible to use an inline variable to drop the extension ".nc" and replace it with ".shp".

Thank you!

Matt Ruch
GIS Analyst
Brown & Caldwell
0 Kudos
10 Replies
deleted-user-XuRyPg9pv1OY
Deactivated User
Thank you again, Dale.

This has been a difficult entry into Python, but after a few more hours of research and learning, I was able to make this work:

base("%Output From Clip%")

def base(filename):
  import os
  fcName = os.path.basename(filename)
  part = fcName.split('_')
  return part[0]

I like Python.

Matt Ruch
0 Kudos