用于复制文件夹

时间:2015-07-23 13:00:36

标签: batch-file cmd copy xcopy robocopy

我在rarme.txt文件中有文件列表路径。 如:

  • D:\ Test \ Bin \ test.dll
  • D:\ Test \ Bin \ test.exe
  • D:\ Test \ Image \ House \ Door.bmp
  • d:\贝塔\ AppHouse.dll

现在如何复制只有一个或两个升级文件夹的文件

代表:如果是

  

d:\测试\ BIN \ Test.dll的

如何在test.dll文件夹中复制Bin文件?

以及

的情况
  

d:\测试\图片\屋\ Door.bmp

如何在door.bmp内复制Image\House Folder

此bat脚本将文件复制到位置D:\ForPatch并将其命名为

Rem Copying files to folder
pause
for /f "tokens=*" %%i in (rarme.txt) do xcopy "%%i" "D:\ForPatch" /s
pause
cd D:\ForPatch
pause
rar a  -ep1 -r Patch.rar *.*
pause

1 个答案:

答案 0 :(得分:0)

希望我理解你的目标:

@ECHO OFF >NUL
SETLOCAL enableextensions
Rem Copying files to folder
for /f "tokens=*" %%i in (rarme.txt) do (
  for /f "tokens=1,* delims=/\" %%J in ("%%~pi") do (
    echo if not exist "D:\ForPatch\%%~K" mkdir "D:\ForPatch\%%~K" 2>NUL
    echo copy /B "%%~i" "D:\ForPatch\%%~K%%~nxi"   
  )
)

请注意,操作mkdircopy /B命令仅用于echo以进行调试。在调试之前删除echo 使用您的数据输出

==>D:\bat\SO\31588128.bat
if not exist "D:\ForPatch\Bin\" mkdir "D:\ForPatch\Bin\"
copy /B "D:\Test\Bin\test.dll" "D:\ForPatch\Bin\test.dll"
if not exist "D:\ForPatch\Bin\" mkdir "D:\ForPatch\Bin\"
copy /B "D:\Test\Bin\test.exe" "D:\ForPatch\Bin\test.exe"
if not exist "D:\ForPatch\Image\House\" mkdir "D:\ForPatch\Image\House\"
copy /B "D:\Test\Image\House\Door.bmp" "D:\ForPatch\Image\House\Door.bmp"
if not exist "D:\ForPatch\" mkdir "D:\ForPatch\"
copy /B "D:\Beta\AppHouse.dll" "D:\ForPatch\AppHouse.dll"

然后脚本的下一个操作变体应该起作用,假设rar命令是正确的(没有测试,因为我没有安装rar)。

@ECHO OFF >NUL
SETLOCAL enableextensions
Rem Copying files to folder
for /f "tokens=*" %%i in (rarme.txt) do (
  for /f "tokens=1,* delims=/\" %%J in ("%%~pi") do (
    if not exist "D:\ForPatch\%%~K" mkdir "D:\ForPatch\%%~K" 2>NUL
    copy /B "%%~i" "D:\ForPatch\%%~K%%~nxi"   
  )
)
pushd D:\ForPatch
pause
rar a  -ep1 -r Patch.rar *.*
pause
popd