# Batch to find and copy files



## pure_evil020 (Jul 31, 2008)

Hi, I need to make up a simple batch file to search through its current directory, and all sub-directories for files with a certain extension type (*sib), make a folder in it's current directory, then copy all the files it finds to that folder, then open that folder for the user to view.

I am familiar with a way to search the same way to delete files, but not sure how to go about finding and copying the files instead...
Would someone be able to show me how to code this?


----------



## Squashman (Apr 4, 2003)

Here is the basic code you need. I think you can probably extrapolate from this.

```
FOR /F "tokens=*" %%A IN ('dir /b /a-d /s *.sib') DO copy "%%A" C:\directory1\
```


----------



## Ent (Apr 11, 2009)

An alternative, which may or may not be better for you, is the following.


```
FOR /R %%A IN (*.sib) DO copy "%%A" C:\directory1\
```
As you can probably guess C:\directory1\ should be replaced by the directory you want to copy the .sib files to.


----------



## Squashman (Apr 4, 2003)

I like ENT's solution better. I always forget about the /R option with For loops.


----------

