简体   繁体   English

使用Xcopy或其他复制目录中的相似文件夹

[英]Using Xcopy or other to copy similar folders within directory

I have one directory with several folders with names like 'MAPAS_10452; 我有一个目录,其中包含几个名为'MAPAS_10452的文件夹; MAPAS_21685; MAPAS_21685; MAPAS_22731' and os on... Inside every folder I have several folders, but I just want to copy the contents of one of them, the folder 'NOVOS'. MAPAS_22731'和操作系统...在每个文件夹中,我都有几个文件夹,但是我只想复制其中一个文件夹“ NOVOS”的内容。

Is it possible to use Xcopy, batch file or other option to copy just The contents of the folder I want, for evey folder 'MAPAS_XXXXX' I have ? 是否可以使用Xcopy,批处理文件或其他选项来仅复制我想要的文件夹的内容(对于我拥有的evey文件夹“ MAPAS_XXXXX”)?

The result would be: MAPAS_10452/NOVOS MAPAS_21685/NOVOS MAPAS_22731/NOVOS 结果将是:MAPAS_10452 / NOVOS MAPAS_21685 / NOVOS MAPAS_22731 / NOVOS

  1. As for /? 至于for /? help says you should put the path in parentheses. 帮助说您应该将路径放在括号中。
  2. Add a wildcard to enumerate the folder contents: * 添加通配符以枚举文件夹内容: *
  3. Use only the name of parent folder to construct the new path: %%~nf 仅使用父文件夹的名称来构造新路径: %%~nf
  4. Check if the NOVOS subfolder actually exists. 检查NOVOS子文件夹是否实际存在。
  5. For flexibility use %USERPROFILE% system variable 为了灵活%USERPROFILE%使用%USERPROFILE%系统变量
  6. Use xcopy /s and add a trailing slash to the second argument to indicate it's a folder 使用xcopy /s并在第二个参数后添加斜杠以指示它是文件夹
  7. [Optional] Use doubleqoutes to process file/folder names with spaces [可选]使用doubleqoutes处理带空格的文件/文件夹名称

for %%f in ("%USERPROFILE%\Desktop\MapasSAAS\*") do (
    if exist "%%f\NOVOS" (
        xcopy /s "%%f\NOVOS" "%USERPROFILE%\Desktop\folder\%%~nf\NOVOS\\"
    )
)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM