Problem in concatenating multiple files from subdirectories

I want to concatenate multiple files recursively from sub-directories intoone file in Linux.

I saved the following script as script.sh in $HOME/testing1 where I have several subdirectories and .txt files into them. I ran script.sh from the command prompt of $HOME/testing1 as ./script.sh. But it deleted all the files from my sub-directories. Can anybody tell me what was wrong and what should be the correct script?

The only messages I got:

cat: file11.txt: input file is output file
cat: file22.txt: input file is output file
......
......

Here is the script I have used:

logdir=$HOME/testing1 ## adjust to taste
for dir in "$logdir"/*/
do
(
cd "$dir"
files=( *.txt )
cat "${files[@]}" > "${PWD##*/}.txt"
rm "${files[@]}"
)
done

The error shown is clear, isn't it ?
Use a temp file (and i suppose the globbing is on)

F="${PWD##*/}"
cat *.txt > "$F" && mv "$F" "$F.txt"

@frans
Thanks for your posting. It will be great if you could write the entire code as I do not know much about shell scripting. Thanks in advance.

You never will if you expect everyone to do everything for you.

Now would be a good time to start learning.