@echo off
for /f %%i in ('dir /s /b "*.txt"') do (ren "%%~pi%%~ni.txt" "%%~ni"
copy "%%~pi%%~ni.txt" "out\%%~ni.txt")