xcopy批处理文件夹树

xcopy batch folder tree

S:
cd \newclients
xcopy "s:\clients\*\MER" . /s /d
pause

这是我的批处理文件。在我的文件夹树中,我们有客户端,然后命名文件夹,然后命名 MER 文件夹。我希望能够在目录中搜索 MER 文件夹,并复制该文件夹及其前面的客户端名称。有没有办法用批处理文件做到这一点?

使用 if exist 应该可以做到。

pushd "s:\newclients"
for /f "delims=" %%f in ('dir /b /ad "s:\clients\*"') do (
if exist "s:\clients\%%f\MER\nul" ( xcopy "s:\clients\%%f\MER" "s:\newclients" /s /d )
)
popd
pause

注意:如果是 check folder,请添加斜杠,即。 if exist "s:\clients\%%f\MER\" ...if exist "s:\clients\%%f\MER\nul" ...

要取消有关目的地 file/folder 的提示,请在 xcopy 中添加 /I

/I    If in doubt always assume the destination is a folder
      e.g. when the destination does not exist.