Assuming you have a target directory in mind (C:\Target) and all of the .txt files are under the C:\Tree directory, the following command would get a list of all of the .txt files and copy them to your desired destination:
for /F "delims=" %a in ('dir /s /b "C:\Tree\*.txt" ') do (copy "%a" "C:\Target")
I put double-quotes around parameters that may contain spaces.
Performs a for loop parsing text. By default, tokens will be split on spaces into variables %a, %b, %c, etc. Since we do not want this behavior, I specified:
Which means no delimiters. %a will be the variable containing each line of text from the output of our command. The command I used was:
dir /s /b "C:\Tree\*.txt"
This performs a directory listing of all files matching *.txt under the C:\Tree folder. The /s flag performs recursively, searching inside of all subdirectories/subfolders. The /b flag outputs the listing in a "bare" format, which basically just lists the file and path. The output looks like:
And of course:
copy "%a" "C:\Target"
Copies file signified by the %a variable to the C:\Target directory. The for loop basically executes the following commands:
copy "C:\Tree\animals\hippopotamus.txt" "C:\Target"
copy "C:\Tree\animals\lion.txt" "C:\Target"
copy "C:\Tree\animals\dog\poodle.txt" "C:\Target"
copy "C:\Tree\animals\dog\terrier.txt" "C:\Target"
copy "C:\Tree\food\fruit\apple.txt" "C:\Target"
copy "C:\Tree\food\fruit\orange.txt" "C:\Target"
copy "C:\Tree\food\vegetables\borcolli.txt" "C:\Target"
copy "C:\Tree\food\vegetables\carrot.txt" "C:\Target"
copy "C:\Tree\food\vegetables\corn.txt" "C:\Target"
For more help on DIR options or FOR loops in Windows Command Prompt (CMD), you can type
help dir or
help for. Beware, the FOR loop help page is quite lengthy. ;)