首页 > 代码库 > 批处理复制文件(文件夹)排除某目录,某些类型(草稿)
批处理复制文件(文件夹)排除某目录,某些类型(草稿)
@echo off REM 查询字符串是否包含某字符串 REM @echo off & SET 变量1=C:\你妹D\大调 REM echo %变量1%|find /i "C:\你妹D">nul 2>nul&&echo true||echo false REM pause>nul set pathDst=C:\Users\Administrator\Desktop\Dst set pathSrc=E:\Src REM =================需要排除的目录或者文件类型================= set excludeDir=obj, set excludeFile=pdb cs csproj user Rem =================清空目标文件夹所有子文件夹和文件================= if exist "%pathDst%" ( echo 目标文件夹已存在! cd /d "%pathDst%" for /d %%i in (*) do ( rd /s /q "%%i" del /a /f /q *.* ) echo 目标文件夹清空完成! ) REM 复制所有文件夹以及文件xcopy /y /e /h %pathSrc% %pathDst% >nulecho 复制所有 for %%c in (%excludeFile%) do (del "%pathDst%\*.%%c" ) for /d /r %pathDst% %%i in (*) do ( setlocal enabledelayedexpansion set "aa=%%i" REM set aa=!aa:%pathDst%=! if exist "!aa!" ( set "A1=!aa!" set "A2=%pathDst%\obj" set "EXISTS_FLAG=false" echo "!A1!"|find /i "!A2!" >nul 2>nul&& set "EXISTS_FLAG=true"||set "EXISTS_FLAG=false" if !EXISTS_FLAG!==true ( echo !A1! rd /s /q "!A1!" ) else ( for %%c in (%excludeFile%) do (del "!A1!\*.%%c" ) ) ) endlocal ) echo 完成 pause>nul rem echo %pathSrc% Rem =================源文件夹及子文件夹================= REM for /r %pathSrc% %%i in (*.txt *.jpg *.png) do ( REM echo E:%%~pi REM set var=!var:*%cd%=! REM ) REM Rem =================字符串替换,源字符串不变================= REM set aa=伟大的中国!我为你自豪! REM echo 替换前:%aa% REM echo 替换后:%aa:中国=中华人民共和国% REM echo aa = %aa% REM set "aa=%aa:中国=中华人民共和国%" REM echo aa = %aa% REM Rem =================遍历所有的子目录(方法1)================= REM for /f "delims=" %%a in (‘dir /ad/s/b %pathSrc%‘) do ( REM rem 获取文件夹完整路径(最后不带\) REM echo %%~a REM rem 获取文件夹完整路径(最后不带\) REM echo %%a REM rem 回去文件夹名称 REM echo %%~na REM ) Rem =================遍历所有的子目录(方法2)并复制所有目录================= REM set EXISTS_FLAG=false REM for /d /r %pathSrc% %%i in (*) do ( rem echo %%i REM setlocal enabledelayedexpansion REM set "aa=%%i" rem echo !aa! REM set aa=!aa:%pathSrc%=! rem echo !aa! rem echo %pathDst%!aa! REM if not exist "%pathDst%!aa!" ( REM set "A1=%pathSrc%!aa!" REM set "A2=%pathSrc%\obj" REM set "EXISTS_FLAG=false" REM =================搜索某字符串是否包含另一个字符串================= REM echo "!A1!"|find /i "!A2!" >nul 2>nul&& set "EXISTS_FLAG=true"||set "EXISTS_FLAG=false" REM echo !EXISTS_FLAG! REM if !EXISTS_FLAG!==true ( REM echo "%pathSrc%!aa!" REM echo "%pathSrc%\obj" REM ) else ( REM md "%pathDst%!aa!" REM for %%c in (%excludeFile%) do (REM xcopy /s/e/c "!A1!\*.%%c" "%pathDst%!aa!"REM ) REM ) REM ) REM endlocal REM ) pause
批处理复制文件(文件夹)排除某目录,某些类型(草稿)
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。