Model Builder - using Folder name as output file name

6902
10
Jump to solution
10-09-2012 12:19 PM
SteffenCornell
New Contributor II
Hi,

I have put together a model that takes all of the shapefiles in a folder and merges them together.  I basically need to know how to use the name of the folder in the name of the output merged file.  

For instance, let's say that I have a folder with a directory of "G:\GIS\Data\Birds".  So the folder "Birds" is my input folder and includes shapefiles of "robins.shp" and "sparrows.shp".  I want the output name to be "Birds_merged.shp" or "Input Folder Name & Birds".

I have tried using inline variables but then I get the entire directory for the input folder.  Is there a way to access the name property of a folder and use it in the model?

Thanks.
1 Solution

Accepted Solutions
MarcinGasior
Occasional Contributor III
You can use Calculate Value model-only tool to extract last folder name from path.
It can be done using the following expression in this tool:
"%Value%".split("\\")[-1]
where %Value% is a PATH output from Parse Path.

Here's an example of model (which uses preconditions to ensure that folder name variable was calculated before using it):
[ATTACH=CONFIG]18316[/ATTACH]

View solution in original post

10 Replies
JonathanQuinn
Esri Notable Contributor
Are you iterating through multiple folders, and then within each folder, iterating through the shapefiles within the folder?  So you essentially want to capture the last folder within the directory?
0 Kudos
SteffenCornell
New Contributor II
I am iterating through multiple subfolders yes but the folder name that I want to capture is the one that holds all of the subfolders.
0 Kudos
MarcinGasior
Occasional Contributor III
You can use Calculate Value model-only tool to extract last folder name from path.
It can be done using the following expression in this tool:
"%Value%".split("\\")[-1]
where %Value% is a PATH output from Parse Path.

Here's an example of model (which uses preconditions to ensure that folder name variable was calculated before using it):
[ATTACH=CONFIG]18316[/ATTACH]
SteffenCornell
New Contributor II
Ok, so that worked somewhat.  Only problem is it calculated the value of one folder higher in the hierarchy then I wanted.  I switched the Parse Path type to "Name" instead of "Path" and it worked perfectly.  Thanks much for the help.
Neha-
by
New Contributor II

Hi Steffen,

Is it possible for you to share your model ?

Thanks,

Neha

0 Kudos
SteffenCornell
New Contributor II

I can sure try.  Do you have an email address?

0 Kudos
Neha-
by
New Contributor II

Thanks Steffan for your swift response.

My email id nsharma2407@gmail.com

0 Kudos
RegieAlam
New Contributor

Hi Steffen. Would it be possible to attach a screenshot of your model?

0 Kudos
SteffenCornell
New Contributor II

0 Kudos