Skip to content
  • Home
  • About
    • Privacy Policy
    • Disclaimer
    • Terms and Conditions
  • Contact Us
Geoscience.blogYour Compass for Earth's Wonders & Outdoor Adventures
  • Home
  • About
    • Privacy Policy
    • Disclaimer
    • Terms and Conditions
  • Contact Us
Posted on January 6, 2023 (Updated on July 18, 2025)

How to remove underscore from filename in directory using modelbuilder

Hiking & Activities

Ditching the Underscore: A ModelBuilder Trick for Tidy Filenames

Let’s face it: messy filenames can be a real headache, especially when you’re juggling tons of GIS data. Underscores, while sometimes necessary, can clutter things up. Ever wished you could just wave a magic wand and get rid of them all in one go? Well, with ArcGIS’s ModelBuilder, you practically can! It’s like having a little robot assistant to clean up your digital workspace.

ModelBuilder is basically a visual way to string together geoprocessing tools in ArcGIS i. Think of it as a flowchart for your GIS tasks. Instead of clicking through menus over and over, you build a model once, and then let it run. It’s perfect for those repetitive jobs that make you want to pull your hair out.

So, how do we use this magic to zap those pesky underscores? Here’s the breakdown:

  • Fire up ModelBuilder: In ArcMap or ArcGIS Pro, go to Geoprocessing > ModelBuilder i. A shiny, blank canvas awaits.

  • Grab the “Iterate Files” tool: This is the workhorse that goes through all the files in your chosen folder. You’ll find it under Insert > Iterators > Files i. Drag it onto your ModelBuilder window.

  • Tell “Iterate Files” where to look: Double-click the “Iterate Files” box to open its settings. Point it to the folder holding your files. Want to be picky? Use the “Wildcard” option to only grab certain file types, like “*.shp” for shapefiles i. Leave it blank to grab everything.

  • Bring in the “Rename” tool: Search for “Rename” in the “Tools” pane and drag it in i. This is the tool that actually does the renaming.

  • Connect the dots: Now, drag a line from the “Name” output of the “Iterate Files” tool to the “Input Dataset” of the “Rename” tool i. This tells the Rename tool which files to work on.

  • The underscore-busting magic: This is where things get interesting. We need to tell the “Rename” tool how to rename the files.

    • Option 1: “Calculate Value” to the rescue: This is my preferred method. Add the “Calculate Value” tool to your model i. Connect the “Name” output from “Iterate Files” to it. Now, in the “Calculate Value” settings, you’ll write a tiny bit of Python code to remove the underscores. The expression would look something like this: “%Name%”.replace(“_”,””). Make sure you set the “Data Type” to “String”. Finally, tell the “Rename” tool to use the output of the “Calculate Value” tool for the new filename.

    • Option 2: A shortcut (maybe): In the “New Name” field of the “Rename” tool, you might be able to directly use something like “%Name:replace(_,”)%”. This should tell it to replace underscores, but sometimes it doesn’t work as expected. The “Calculate Value” method is generally more reliable.

  • Pick a spot for the renamed files: Make sure the output workspace is set correctly. This is where the renamed files will end up. It can be the same as the input folder, which means you’ll be renaming the files in place.

  • Double-check your work: Hit the “Validate” button to make sure everything is connected properly and there are no obvious errors i.

  • Let it rip!: Click “Run” and watch ModelBuilder go to work i. It’ll loop through each file, strip out the underscores, and rename the files.

  • A Few Words of Caution

    • File extensions are your friends: This process only renames the base filename, leaving the extension (like “.shp”) untouched.
    • Don’t overwrite!: Be super careful when renaming files in the same folder. If you end up with two files having the same name, you could lose data. Consider adding a counter or something to make sure each filename is unique.
    • Things go wrong: For serious models, add some error handling to deal with unexpected problems.
    • Python power: While ModelBuilder is great, Python scripting gives you even more control for complex renaming tasks. It’s worth learning if you’re doing a lot of this kind of thing.

    Real-World Example

    Let’s say you’ve got a folder full of shapefiles named like “building_parcels.shp”, “street_network.shp”, and “water_bodies.shp”. Run this ModelBuilder tool, and poof, they become “buildingparcels.shp”, “streetnetwork.shp”, and “waterbodies.shp” – nice and tidy!

    The Takeaway

    ModelBuilder is a fantastic tool for automating all sorts of GIS tasks, and removing underscores from filenames is just one example. By combining the “Iterate Files” and “Rename” tools with a little bit of Python magic, you can keep your data organized and save yourself a ton of time. Trust me, your future self will thank you!

    You may also like

    Field Gear Repair: Your Ultimate Guide to Fixing Tears On The Go

    Outdoor Knife Sharpening: Your Ultimate Guide to a Razor-Sharp Edge

    Don’t Get Lost: How to Care for Your Compass & Test its Accuracy

    Disclaimer

    Our goal is to help you find the best products. When you click on a link to Amazon and make a purchase, we may earn a small commission at no extra cost to you. This helps support our work and allows us to continue creating honest, in-depth reviews. Thank you for your support!

    Categories

    • Climate & Climate Zones
    • Data & Analysis
    • Earth Science
    • Energy & Resources
    • Facts
    • General Knowledge & Education
    • Geology & Landform
    • Hiking & Activities
    • Historical Aspects
    • Human Impact
    • Modeling & Prediction
    • Natural Environments
    • Outdoor Gear
    • Polar & Ice Regions
    • Regional Specifics
    • Review
    • Safety & Hazards
    • Software & Programming
    • Space & Navigation
    • Storage
    • Water Bodies
    • Weather & Forecasts
    • Wildlife & Biology

    New Posts

    • How Much Does a Mongoose Bike Really Cost? Let’s Break It Down
    • Backpack Lightweight Insulated Organizers Sunflowers – Review
    • Hat-titude Activated: My Take on the Lightning Tennis Bucket Hat
    • Ditching That Disc: A No-Sweat Guide to Removing Shimano Centerlock Rotors
    • ROCKY Original Ride FLX Western Boot: A Classic Reimagined for the Modern Cowboy (or City Slicker!)
    • Rocky Nowake Water Shoes: My New Go-To for Water Adventures (and Unexpected Spills!)
    • Is Rainier Beer Still Around? A Pacific Northwest Love Story
    • BTCOWZRV Water Shoes: Retro Style Meets Aquatic Adventure!
    • CMP Rigel Trekking Shoes: Stylish Comfort on the Trail? My Take
    • Sharing the Road: How Much Space Should You Really Give a Cyclist When Overtaking?
    • DFWZMQTG “Outer Wear” Slippers: Luxury or Lunacy? (A Hands-On Review)
    • Rab Women’s Muztag GTX Gaiters: My Reliable Mountain Companion
    • What’s in a Name? Peeling Back the Layers of “Mr. Fisher” and “Tangerine”
    • YUYUFA Hiking Backpack Travel Capacity – Tested and Reviewed

    Categories

    • Home
    • About
    • Privacy Policy
    • Disclaimer
    • Terms and Conditions
    • Contact Us
    • English
    • Deutsch
    • Français

    Copyright (с) geoscience.blog 2025

    We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “Accept”, you consent to the use of ALL the cookies.
    Do not sell my personal information.
    Cookie SettingsAccept
    Manage consent

    Privacy Overview

    This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
    Necessary
    Always Enabled
    Necessary cookies are absolutely essential for the website to function properly. These cookies ensure basic functionalities and security features of the website, anonymously.
    CookieDurationDescription
    cookielawinfo-checkbox-analytics11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Analytics".
    cookielawinfo-checkbox-functional11 monthsThe cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional".
    cookielawinfo-checkbox-necessary11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary".
    cookielawinfo-checkbox-others11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Other.
    cookielawinfo-checkbox-performance11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Performance".
    viewed_cookie_policy11 monthsThe cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data.
    Functional
    Functional cookies help to perform certain functionalities like sharing the content of the website on social media platforms, collect feedbacks, and other third-party features.
    Performance
    Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.
    Analytics
    Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics the number of visitors, bounce rate, traffic source, etc.
    Advertisement
    Advertisement cookies are used to provide visitors with relevant ads and marketing campaigns. These cookies track visitors across websites and collect information to provide customized ads.
    Others
    Other uncategorized cookies are those that are being analyzed and have not been classified into a category as yet.
    SAVE & ACCEPT