# Solved: Xcopy batch how to move same files in multi folders into 1 folder



## Reconsniper1 (Apr 17, 2008)

Okay...new question. I have looked at the flags for Xcopy and experimented around. My problem is i'm trying to copy all the .doc files in the directory and subdirectories (ex: c:\test\testa\testb etc) underneath it, have it put those documents in a c:\test1 but without the file structure. I do not want the subdirectories, but just the files.

I've tried xcopy /s c:\test\*.doc c:\test1

It will give me the files but it will have them in the same file structure. 

You guys are awesome and thanks for your help!


----------



## devil_himself (Apr 7, 2007)

Here ya go


```
@echo off
setlocal
pushd "c:\test"
for /f "tokens=*" %%a in ('dir /b /a-d /s *.doc') do copy "%%a" "c:\test1"
popd
```


----------



## Reconsniper1 (Apr 17, 2008)

Works awesome! I have to google the use of Tokens and stuff b/c that seems to be used in a lot of the more complex batches. Thanks again!


----------



## devil_himself (Apr 7, 2007)

*Delims*: used to break the line up into chunks that you can reference with variables %%i %%j %%k ...
*Tokens*: used so you can tell the FOR command how many chunks you want to break it up into and how many will be handled by variables

For More Info Open Command Prompt And Type - *For /?*


----------

