# Batch File Renamer

**URL:** https://boards.straightdope.com/t/batch-file-renamer/617188
**Category:** Factual Questions
**Created:** [March 29, 2012, 6:45pm UTC](https://boards.straightdope.com/t/batch-file-renamer/617188 "2012-03-29T18:45:37Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![drewtwo99](https://avatars.discourse-cdn.com/v4/letter/d/d07c76/32.png) [@drewtwo99](https://boards.straightdope.com/u/drewtwo99)
#### Post date: [March 29, 2012, 6:45pm UTC](https://boards.straightdope.com/t/batch-file-renamer/617188/1 "2012-03-29T18:45:37Z")

</div>

Hey all, I have a question for you.

I need a program that can rename large amounts of files based on the following criteria…

A program I use that dumps images dumps them in the following way…

RECID\_COMPTYPE\_IMAGETYPE\_####.gif

Where RECID and COMPTYPE are varying different numbers depending on the image, IMAGETYPE is a small string that also varies from image to image. The #### are image index numbers, so they go from 0001 up to whatever the last image dumped is.

Basically, I want to just get rid of the image index #### for all the filenames, but I’m dealing with thousands and thousands of files, so going through and doing it manually would not be feasible.

If it helps, RECID is always 8 chars, COMPTYPE is always 2 chars, and IMAGETYPE is always 3 chars. I think since they are so uniform in length, it should be easy to remove the chars between position x-y, in the file name… but I just don’t know of any programs that do this.

Any ideas? Maybe write a script?

---

<div class="post-metadata">

### Author: ![beowulff](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/beowulff/32/542_2.png) [@beowulff](https://boards.straightdope.com/u/beowulff)
#### Post date: [March 29, 2012, 7:01pm UTC](https://boards.straightdope.com/t/batch-file-renamer/617188/2 "2012-03-29T19:01:07Z")

</div>

What platform?

---

<div class="post-metadata">

### Author: ![redtail23](https://avatars.discourse-cdn.com/v4/letter/r/3e96dc/32.png) [@redtail23](https://boards.straightdope.com/u/redtail23)
#### Post date: [March 29, 2012, 7:09pm UTC](https://boards.straightdope.com/t/batch-file-renamer/617188/3 "2012-03-29T19:09:12Z")

</div>

If you’re on Windows, I’ve used [this one](http://www.fauland.com/af5.htm) for batch file renaming.

If you’re wanting to automate, I think you could write a cmd file using their command line setup.

Or a script would do it, if that floats your boat.

---

<div class="post-metadata">

### Author: ![drewtwo99](https://avatars.discourse-cdn.com/v4/letter/d/d07c76/32.png) [@drewtwo99](https://boards.straightdope.com/u/drewtwo99)
#### Post date: [March 29, 2012, 7:14pm UTC](https://boards.straightdope.com/t/batch-file-renamer/617188/4 "2012-03-29T19:14:45Z")

</div>

I could do it on either Linux or Windows. I’m going to look at the program you linked redtail, see if it can do what I need. Thanks!

---

<div class="post-metadata">

### Author: ![drewtwo99](https://avatars.discourse-cdn.com/v4/letter/d/d07c76/32.png) [@drewtwo99](https://boards.straightdope.com/u/drewtwo99)
#### Post date: [March 29, 2012, 8:16pm UTC](https://boards.straightdope.com/t/batch-file-renamer/617188/5 "2012-03-29T20:16:39Z")

</div>

That program worked wonders! Thanks 🙂

---

<div class="post-metadata">

### Author: ![J-P\_L](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/j-p_l/32/3156_2.png) [@J-P\_L](https://boards.straightdope.com/u/J-P_L)
#### Post date: [March 29, 2012, 9:15pm UTC](https://boards.straightdope.com/t/batch-file-renamer/617188/6 "2012-03-29T21:15:21Z")

</div>

Sounds like you found something you like.

However, another option is [Bulk Rename Utility](http://www.bulkrenameutility.co.uk/Main_Intro.php)

---

<div class="post-metadata">

### Author: ![Fubaya](https://avatars.discourse-cdn.com/v4/letter/f/c2a13f/32.png) [@Fubaya](https://boards.straightdope.com/u/Fubaya)
#### Post date: [March 29, 2012, 10:20pm UTC](https://boards.straightdope.com/t/batch-file-renamer/617188/7 "2012-03-29T22:20:55Z")

</div>

> [@drewtwo99](#):
>
> If it helps, RECID is always 8 chars, COMPTYPE is always 2 chars, and IMAGETYPE is always 3 chars. I think since they are so uniform in length, it should be easy to remove the chars between position x-y, in the file name… but I just don’t know of any programs that do this.
> 
> Any ideas? Maybe write a script?

On Linux, this will work in the bash shell and probably some others I think. cd to the directory then:

\*for i in _.gif; do mv “i" "{i:0:15}.gif”; done_

Change _mv_ to _echo_ to test, it will echo the old filename and the new filename.

This takes a file one at a time and assigns it’s name to the $i variable, then moves it from the full filename to a new file named with the first 16 characters of the old name with .gif tacked on the end. It will go through all gif files in the directory.

# touch 12345678\_12\_123\_0001.gif

# touch 12345679\_12\_123\_0002.gif

# touch 12345670\_12\_123\_0003.gif

# ls -1

12345670\_12\_123\_0003.gif  
12345678\_12\_123\_0001.gif  
12345679\_12\_123\_0002.gif

# for i in \*.gif; do mv “i" "{i:0:15}.gif”; done

# ls -1

12345670\_12\_123.gif  
12345678\_12\_123.gif  
12345679\_12\_123.gif

#

---

<div class="post-metadata">

### Author: ![drewtwo99](https://avatars.discourse-cdn.com/v4/letter/d/d07c76/32.png) [@drewtwo99](https://boards.straightdope.com/u/drewtwo99)
#### Post date: [March 29, 2012, 10:24pm UTC](https://boards.straightdope.com/t/batch-file-renamer/617188/8 "2012-03-29T22:24:56Z")

</div>

J-P-L, that one works even better! Thanks so much 🙂

Fubaya, Thanks! I’ll give that method a try too 🙂

---

<div class="post-metadata">

### Author: ![redtail23](https://avatars.discourse-cdn.com/v4/letter/r/3e96dc/32.png) [@redtail23](https://boards.straightdope.com/u/redtail23)
#### Post date: [March 30, 2012, 6:35pm UTC](https://boards.straightdope.com/t/batch-file-renamer/617188/9 "2012-03-30T18:35:16Z")

</div>

That is a nice utility, **J-P L**!
