|
|
发表于 2023-3-17 17:50:50
|
显示全部楼层
回复 1# oyr520
在你的代码基础上简化一下,使用 findstr /v 排除指定文件和文件夹:- @echo off
- setlocal enabledelayedexpansion
- set "source=%cd%"
- set "destination=C:\test"
- set "excludes=Folder1 Folder2 File1.txt File2.txt"
- if not exist "%destination%" (
- echo Error: test directory does not exist.
- pause
- exit /b
- )
- for /f "delims=" %%i in ('dir /b /a-d "%source%" ^| findstr /v "%excludes%"') do (
- if exist "%destination%\%%i" (
- echo Skipping file: %%i
- ) else (
- robocopy "%source%" "%destination%" "%%i" /njh /njs /ndl /np
- )
- )
- for /f "delims=" %%i in ('dir /b /ad "%source%" ^| findstr /v "%excludes%"') do (
- if exist "%destination%\%%i" (
- echo Skipping folder: %%i
- ) else (
- robocopy "%source%\%%i" "%destination%\%%i" /s /njh /njs /ndl /np
- )
- )
- echo Done!
- pause
- exit /b
复制代码 |
|