# Solved: renaming files with names on a file.



## 450 (Jul 1, 2014)

I'm wondering if it's possible to rename multiple files using dos in a order like you would in a find and replace style. Im currently stuck using the rename command, I can only seem to replace a portion of the name that files have in common for example renaming .txt to .pdf.

Currently I have a few hundred files that I'm trying to organize. Files names are in the following format.
AMTI0032
AJJC0089
GLLC7223
RRJL0202

I have a text file with the names to rename each file with. It would look like this.

Denver AMTI0032
Carwash AJJC0089
summary GLLC7223
Expense RRJL0202

What I'm trying to do here is create a batch to rename each file with its appropriate name.
Not sure if this is possible in msdos. Would there be a better option to achieve this?


----------



## foxidrive (Oct 20, 2012)

It can be done easily with a batch script with the text file you have shown.

Do any of the names have spaces in them though?
Are all the files in a single folder?


----------



## 450 (Jul 1, 2014)

There are no spaces in the files I want to rename. Its just 8 character names 4 letters and 4 numbers, the beginning 4 letters have a (-) in place of one of the letters but its still same format 4 characters followed by 4 numbers. Example AM-C0037.

The names I have in a file that I want to add I would like to add a space between them so its easier to read such as (Gas AM-C0037). But I could live without that space separating the two.


----------



## 450 (Jul 1, 2014)

Sorry I forgot to mention that yes the files are in a single folder.


----------



## foxidrive (Oct 20, 2012)

With your text file, each line having this format (it needs that space between the names) then the code below will rename the files.
Note that you have not included any extension to the filenames and this may need some adjusting if you do have extensions.

Test it on some copies of your files first.


```
name-after name-before
```


```
@echo off
for /f "usebackq tokens=1,*" %%a in ("file.txt") do (
   ren "%%b" "%%a"
)
pause
```


----------



## Squashman (Apr 4, 2003)

Washamein said:


> Not sure if this is possible in msdos.


No not possible with any version of MS-DOS as it only allows for 8.3 file names. You can however do it with Window NT Based batch files.


----------



## 450 (Jul 1, 2014)

I finally got it to work. Had to get rid of a few things on my end. Squashman I see what you were referring to when I tried to combine the names it was too long but I managed to get it to work by adding newname_oldname.

I couldn't get it to work with a space between them. Since I'm fairly new at this i had some issues on my code but foxidrive wrote was correct. I just had to play around with my file I was using with the names I wanted. Did a few test and its all good.

Thanks again foxidrive!


----------



## Squashman (Apr 4, 2003)

Spaces require quotes around them in the batch file.


----------

