用于复制子文件夹内的文件的命令行命令

时间:2015-12-03 12:23:21

标签: windows batch-file cmd batch-processing

使用命令行,我想同时将一个文件复制到文件夹列表中。 例如,我想将E:\HTM.nsf复制到:

E:\Note\A1\note\data1\
E:\Note\A2\note\data1\
E:\Note\A3\note\data1\
E:\Note\A4\note\data1\

我使用XCopy:

E:\>xcopy e:\HTM*.*nsf "\notes\A1\note\data1\"

它的作品,但我想同时将HTM.nsf复制到所有用户(A1到A4)。

1 个答案:

答案 0 :(得分:0)

尝试创建一个像这样的批处理脚本copyfiles.cmd

@echo off
setlocal enabledelayedexpansion
if "%1"=="/restart" goto restart
for /d %%a in (
  "E:\Note\A*"
) do (call %0 /restart %%~fa\note\data1)
goto end

:restart
shift
set targetPath="%1"
echo processing %targetPath% ...
copy e:\HTM*.*nsf %targetPath% /B/Y
exit /b

:end
exit

备注:

  • 路径需要拆分,不能在路径中间使用通配符*
  • 通过在循环中使用E:\Note\A*路径,它找到A1,A2,A3等等,附加路径的其余部分,即表达式%%~fa\note\data1用于完成路径(其中%%~fa是找到的其中一条路径的占位符 - 例如E:\Note\A1
  • 此脚本自行启动,复制命令在标签:restart处发生,并使用exit /b
  • 返回到for循环