【问题标题】:Copy subfolders and files from first level from source to destination location CMD将子文件夹和文件从源位置复制到目标位置 CMD
【发布时间】:2018-09-13 08:18:52
【问题描述】:

我的文件夹层次结构如下:

Sourcedir-
-Folder 1
--File1.xml
--File2.xml
--FolderA
---FileAA.xml
--FolderB
-Folder 2
--File3.xml
--File4.xml
--FolderC
---FileCA.xml
--FolderD
---FileDA.xml

我只想将文件和子文件夹从第一级复制到类似的位置:

DestiDir-
 -Folder 1
 --File1.xml
 --File2.xml
 -Folder 2
 --File3.xml
 --File4.xml

我试图在 cmd 中写一些东西:

@echo off
SETLOCAL ENABLEDELAYEDEXPANSION
SET "sourcedir=C:\sourcedir"
SET "destdir=C:\destdir" 
for /D %%A in ("%sourcedir%") do (
  for /D %%B in ("%%~fA\*") do (
   @echo xcopy /L /I "%%~fB\*.*" "%destdir%"
  )
)

但这个只是将第一级 xml 文件复制到另一个位置,我希望这些文件也具有相同的子文件夹。

【问题讨论】:

  • /E 开关添加到 xcop 行。

标签: batch-file command-line cmd


【解决方案1】:

我找到了使用robocopy mby some1 的解决方案,将来会需要此信息:

SET "sourcedir=C:\Test"
SET "destdir=C:\desti" 
robocopy "%sourcedir%" "%destdir%" /e /LEV:2 /XF "*.txt"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-07-02
    • 2017-10-11
    • 1970-01-01
    • 1970-01-01
    • 2017-03-31
    • 1970-01-01
    • 2021-06-07
    • 2017-05-27
    相关资源
    最近更新 更多