# Solved: Help with a File rename Batch script!



## Dracrius (Sep 7, 2012)

So I have folders full of tv shows and a program that gives them all matching thumbnails but it saves them as .tbn files and my media server wants .jpg. So i wrote this script to run from my vidoes folder which contains all my tv shows.

```
@for /r %%i in (*.tbn) do ren "%%~fi" "%%~ni.jpg"
```
But now I am using xbmc as well and it looks for many thumbnails as .tbn so I want to change the script to rename any .tbn that is not named season00.tbn (00 being any two digits). If anyone could help me code this it would be much appreciated I tried for hours cause I know it should be a very simple if statement added in there but everything I try either stops renaming anything or still renames everything.


----------



## Ent (Apr 11, 2009)

Are you sure that tbn files are actually Jpegs? You can't convert a file from one format to another by merely changing the file extension.

I reckon your best bet would be to use regular expressions, probably with findstr.
This regex string would probably catch the ones you don't want:

```
.*[0-9][0-9].tbn
```


----------



## Dracrius (Sep 7, 2012)

Ok first yes I know they are jpgs I can watch the program I'm using (TV Rename) download the images as jpgs and save them as tbn plus I've been using that script for months. Now I get what your suggesting but I don't really know batch script very well It took me a while to come up with what I have if you could show me the complete code with that regex it may work but my main issue is that the script is searching through hundreds of tv show thumbnails all named {Show} S00E00 {Episode Name}.tbn so who knows if one day I have a episode name that ends with two numbers that expression would skip over it. See I want the script to only skip files that are named season*.tbn no leading characters exactly that because for every tv show season their is one season00.tbn for the season cover art/dvd cover (including a season-specials.tbn in a few shows like doctor who with good specials). Thanks for the attempt and I hope that clarifies what I'm looking for a little more.


----------



## Ent (Apr 11, 2009)

So all files starting with season and ending with .tbn should be ignored?

This should work, though it isn't terribly elegant.


```
@echo off
for /r %%i in (*.tbn) do (
echo %%i | findstr /R [Ss][Ee][Aa][Ss][Oo][Nn].*\.tbn > nul
if ERRORLEVEL 1 ren "%%~fi" "%%~ni.jpg"
)
```


----------



## Dracrius (Sep 7, 2012)

Thanks A lot that worked like a dream!


----------



## Ent (Apr 11, 2009)

You're welcome. 

If your problem has been resolved, as the original poster you and only you can click the "mark solved" button at the top of the thread. This will alert others with the same issue that a possible fix can be found here. Likewise it will help to ensure that our volunteers focus on issues which still lack a solution instead of possibly wasting time here.


----------



## phamhuanmko (Sep 11, 2012)

good


----------

