robocopy /xd 忽略目录列表
robocopy /xd ignores a list of directories
我正在整理一个将源代码树同步到另一个目录的 Powershell 脚本。根据 robocopy /?
:
的输出,它创建了一个要忽略的目录列表
# ----------------------------------------------------------------------------
# Source file directories
# ----------------------------------------------------------------------------
$reactjs = "C:\Users\me\Projects\prj\reactjs"
# ----------------------------------------------------------------------------
# Target directories
# ----------------------------------------------------------------------------
$synergy = "C:\Users\me\Projects\sync\reactjs"
$synReactjs = $synergy + "\prj-JS"
# ----------------------------------------------------------------------------
# Directories to be ignored
# ----------------------------------------------------------------------------
$reactIgnores = @(
$reactjs + "\.git",
$reactjs + "\node_modules",
$reactjs + "\build"
)
# ----------------------------------------------------------------------------
# Copy/sync files
# ----------------------------------------------------------------------------
Robocopy /l $reactjs $synReactjs /mir /xd $reactIgnores
然而,robocopy 立即进入 .git
目录,尽管输出 header 看起来它正确地解析了我的开关:
-------------------------------------------------------------------------------
ROBOCOPY :: Robust File Copy for Windows
-------------------------------------------------------------------------------
Started : Wednesday, October 31, 2018 12:00:32 PM
Source : C:\Users\me\Projects\prj\reactjs\
Dest : C:\Users\me\Projects\sync\reactjs\prj-JS\
Files : *.*
Exc Dirs : C:\Users\me\Projects\prj\reactjs\.git C:\Users\me\Projects\prj\reactjs\node_modules C:\Users\me\Projects\prj\reactjs\build
Options : *.* /L /S /E /DCOPY:DA /COPY:DAT /Z /R:1000000 /W:30
------------------------------------------------------------------------------
New Dir 8 C:\Users\me\Projects\prj\reactjs\
New File 634 .eslintrc.json
New File 206 .gitignore
New File 55 .npmrc
New File 521255 package-lock.json
New File 1015 package.json
New File 1001 package.json.react16
New File 10391 README
New File 1639 README.md
New Dir 9 C:\Users\me\Projects\prj\reactjs\.git\
New File 135 COMMIT_EDITMSG
New File 319 config
New File 73 description
New File 125 FETCH_HEAD
<...>
/xd
开关我错过了什么?它适用于单个目录。
编辑:我包含了 Powershell 标记,因为如果我在命令行中明确包含它们,/xd
会忽略文件列表。通过数组加载它们不起作用。这导致 exc 行(与上面相比):
Exc Dirs : C:\Users\me\Projects\prj\reactjs\.git
C:\Users\me\Projects\prj\reactjs\node_modules
C:\Users\me\Projects\prj\reactjs\build
在
$reactIgnores = @(
$reactjs + "\.git",
$reactjs + "\node_modules",
$reactjs + "\build"
)
尝试输入完整路径。
这个数组对我有用,用单引号转义双引号。您不需要完整路径,我使用了一个 /XD $eXcludeDirectories 命令:
$eXcludeDirectories = @(
'"Folder01"',
'"Folder02"',
'"Folder03"'
)
希望这对其他人有所帮助。
我正在整理一个将源代码树同步到另一个目录的 Powershell 脚本。根据 robocopy /?
:
# ----------------------------------------------------------------------------
# Source file directories
# ----------------------------------------------------------------------------
$reactjs = "C:\Users\me\Projects\prj\reactjs"
# ----------------------------------------------------------------------------
# Target directories
# ----------------------------------------------------------------------------
$synergy = "C:\Users\me\Projects\sync\reactjs"
$synReactjs = $synergy + "\prj-JS"
# ----------------------------------------------------------------------------
# Directories to be ignored
# ----------------------------------------------------------------------------
$reactIgnores = @(
$reactjs + "\.git",
$reactjs + "\node_modules",
$reactjs + "\build"
)
# ----------------------------------------------------------------------------
# Copy/sync files
# ----------------------------------------------------------------------------
Robocopy /l $reactjs $synReactjs /mir /xd $reactIgnores
然而,robocopy 立即进入 .git
目录,尽管输出 header 看起来它正确地解析了我的开关:
-------------------------------------------------------------------------------
ROBOCOPY :: Robust File Copy for Windows
-------------------------------------------------------------------------------
Started : Wednesday, October 31, 2018 12:00:32 PM
Source : C:\Users\me\Projects\prj\reactjs\
Dest : C:\Users\me\Projects\sync\reactjs\prj-JS\
Files : *.*
Exc Dirs : C:\Users\me\Projects\prj\reactjs\.git C:\Users\me\Projects\prj\reactjs\node_modules C:\Users\me\Projects\prj\reactjs\build
Options : *.* /L /S /E /DCOPY:DA /COPY:DAT /Z /R:1000000 /W:30
------------------------------------------------------------------------------
New Dir 8 C:\Users\me\Projects\prj\reactjs\
New File 634 .eslintrc.json
New File 206 .gitignore
New File 55 .npmrc
New File 521255 package-lock.json
New File 1015 package.json
New File 1001 package.json.react16
New File 10391 README
New File 1639 README.md
New Dir 9 C:\Users\me\Projects\prj\reactjs\.git\
New File 135 COMMIT_EDITMSG
New File 319 config
New File 73 description
New File 125 FETCH_HEAD
<...>
/xd
开关我错过了什么?它适用于单个目录。
编辑:我包含了 Powershell 标记,因为如果我在命令行中明确包含它们,/xd
会忽略文件列表。通过数组加载它们不起作用。这导致 exc 行(与上面相比):
Exc Dirs : C:\Users\me\Projects\prj\reactjs\.git
C:\Users\me\Projects\prj\reactjs\node_modules
C:\Users\me\Projects\prj\reactjs\build
在
$reactIgnores = @(
$reactjs + "\.git",
$reactjs + "\node_modules",
$reactjs + "\build"
)
尝试输入完整路径。
这个数组对我有用,用单引号转义双引号。您不需要完整路径,我使用了一个 /XD $eXcludeDirectories 命令:
$eXcludeDirectories = @(
'"Folder01"',
'"Folder02"',
'"Folder03"'
)
希望这对其他人有所帮助。