复制粘贴到记事本,另存为xx.bat,编码选ANSI
@echo off
rem 查找/搜索指定目录下指定扩展名/后缀名的文件并按原目录结构移动到新的目录里
mode con lines=3000
set #=Any question&set @=WX&set $=Q&set/az=0x53b7e0b4
title %#% +%$%%$%/%@% %z%
cd /d "%~dp0"
set "oldfolder=D:\xxx\源文件夹"
set "newfolder=D:\yyy\新文件夹"
set ext=*.dwg
set "batfile=.\#restore.bat"
>"%batfile%" echo;@echo off
if not exist "%oldfolder%" (echo;"%oldfolder%" not found&goto end)
for /f "delims=" %%a in ('dir /a-d/b/s "%oldfolder%\%ext%" 2^>nul') do (
set "file=%%a"
set "name=%%~nxa"
set "oldpath=%%~dpa"
setlocal enabledelayedexpansion
set "newpath=!oldpath:%oldfolder%=%newfolder%!"
if not exist "!newpath!" md "!newpath!"
echo;"!file!" --^> "!newpath!"
move /y "!file!" "!newpath!"
>>"%batfile%" echo;move /y "!newpath!!name!" "!oldpath!"
endlocal
)
>>"%batfile%" echo;pause
:end
echo;%#% +%$%%$%/%@% %z%
pause
exit