# copy files with same name but different extension



## andykestrel (May 24, 2011)

HI,

I have aproblem in that i need 'pairs' of files in one folder. However I have two folders at the moment, lets say i have c:\gifs and c:\tabs

C:\gifs contains a set of files called one.gif, three.gif, four.gif, seven.gif.........

C:\tabs contains a set of files called one.tab, two.tab, three.tab, four.tab, five.tab etc etc

I need to copy files from C:\tabs to C:\gifs if the filename (ignoring the extension) is the same, so that i end up with c:\gifs containing:

one.gif, one.tab, three.gif, three.tab, four.gif, four.tab, seven.gif, seven.tab........

not sure if i can do this on one dos command or need a little batch file, trying to find a solution using FOR etc...

Any Ideas? Many Thanks

Andy


----------



## Squashman (Apr 4, 2003)

Just off the top of my head. Did not test this.


```
@Echo Off & SetLocal EnableExtensions
pushd c:\tabs
For /F "tokens=*" %%I IN ('dir /a-d /b *.tab') DO (
	IF EXIST "C:\gifs\%%~nI.gif" copy "%%~I" C:\gifs\ 
)
```


----------



## andykestrel (May 24, 2011)

HI Squashman,

Thats absolutly stupendous, many thanks, fully tested and ok!
Cheers

Andy


----------

