# Batch to copy the name of .avi file to a .srt file



## AdamBrave (Oct 18, 2012)

Hi,

I have done a batch to copy the name of a .avi file to a .srt file. The problem is that the .srt file became with the ".avi" string within the name. Example:

Before my batch file:
matrix.avi
subtitles.srt

After my batch file:
matrix.avi
matrix.avi.srt

I tried to erase the ".avi" string in the .srt file but I have no sucess. Here is the code:


```
@echo off
dir *.mp3 /b "C:\Batch files" >>filelist.txt


for /f "tokens=1* delims=|" %%a in (filelist.txt) do (
       
      ren *.srt "%%a".srt
)

del filelist.txt
```
Can someone help me please?


----------



## bliss-II (Oct 18, 2012)

You don't need a script for this.


```
C:\Users\Charlie\temp>dir /b
1.avi
2.avi
3.avi

C:\Users\Charlie\temp>ren *.avi *.srt

C:\Users\Charlie\temp>dir /b
1.srt
2.srt
3.srt

C:\Users\Charlie\temp> :)
```


----------



## AdamBrave (Oct 18, 2012)

What??

That will rename the .avi files...don't make sense Oo
I want to rename the .srt files...


----------



## Squashman (Apr 4, 2003)

Your the one using the rename command in your BATCH CODE when your description says you want to Copy! How much sense does that make!!!!


----------



## AdamBrave (Oct 18, 2012)

I don't want to copy the file. I want a batch that *copy the name* of a .avi file to a .srt file. 
To change the name of a file you need to use the command "ren" right?


----------



## bliss-II (Oct 18, 2012)

Misunderstood, sorry. Your FOR loop is a little wonky. (The REN threw me off a little too.)

This should work for you.



```
for /f "tokens=1,2 delims=." %%a in (filelist.txt) do (

      echo | set /p="" > %%a.srt
)
```
Basically, it assigns 2 variables for each line. %%a, which is the filename, and %%b, the extension. The echo command writes exactly nothing to filename.srt.


----------



## Squashman (Apr 4, 2003)

Bliss, you should use the command modifiers for the token variable. If the filename has more than 1 period it will screw up the filenames. Read the bottom of the FOR help file.


----------



## foxidrive (Oct 20, 2012)

Same as at dostips.


```
@echo off
for %%a in (*.avi) do ren *.srt "%%~na.srt"
```


----------

