@echo off
set "file_name=FM"
set "DstDir=d:\test\指定文件夹"
if not exist "%DstDir%" md "%DstDir%"
for /r %%a in ("*%file_name%*") do (
set "_path=%%~dpa"
setlocal enabledelayedexpansion
if /i "!_path:%DstDir%=!" equ "!_path!" (
set "_path=!_path:%~dp0=!"
set "_path=!_path:\=-!"
echo;f|xcopy "%%a" "%DstDir%\!_path!%%~nxa" /y
)
endlocal
)
pause