批处理复制文件(文件夹)排除某目录,某些类型(草稿)

    @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% >nul
echo 复制所有
 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

 

上一篇:如何在VS2005中自动添加事件处理函数?


下一篇:C# Excel数据验重及Table数据验重