# Changing File Names Using DOS



## Dustin Cook (Dec 26, 2003)

Hi.

I have a load of files which all begin with:

N341_00702202....

But I want to change them all to be

N341_*2*00702202....

Does anyone know how to achieve this using dos?

Cheers,
DC.


----------



## Squashman (Apr 4, 2003)

I would just use a file rename utility. There are plenty of them out there. Yes it can be done natively with a dos batch file but why write one for a one shot deal. As long as you just want the character after the underscore changed to a 2 on all files it would be easy enough to do with a batch file.

I use a program called V-The File Viewer to accomplish this task though. Would take me all of 5 seconds.


----------



## Squashman (Apr 4, 2003)

I think this should work. Just whipped it out real quick.

```
@echo off
TITLE Re-name Filenames

:: Set _iFolder to the folder name with all your files.  Don't put your batch file here.
set _iFolder=C:\pathtofiles

pushd "%_iFolder%"

:: change to the appropriate file extension or just put in an asterisk
FOR /F "tokens=1* Delims=_" %%A IN ('dir /b /a-d N341_00702202*.txt') DO (
	rename "%%A"_"%%B"  "%%A"_2"%%B"
	)
popd
```


----------

