[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

[文本处理] 【已解决】批处理:批量替换特定文件夹内的内容

C盘根目录有一命名为“数据”的文件夹,其内有12个子文件夹,分别命名为“文件1”、“文件2”...“文件12 ”,
这12个子文件夹内各有210个子文件夹,分别命名为001 002...210,
这210个子文件夹内各有一命名为Data的子文件夹,
即共有2520个“Data”文件夹。
现在,C盘根目录有一命名为“Data”的文件夹,欲用该“Data” 内的内容,替换上述2520个“Data” 内的内容 (即:先删除2520个“Data” 内的内容,再写入C盘根目录“Data” 内的内容)。这样的批处理如何写?
注:“Data” 内的文件,名称相同。

自己写了一个替换代码,只替换“文件1”中“001"里的"Data",但不知道如何加一个循环,替换其余2519个。
  1. @echo off                        
  2. type c:\data\0-texts.cs>c:\数据\文件1\001\data\0-texts.cs  
  3. type c:\data\1-texts.cs>c:\数据\文件1\001\data\1-texts.cs
  4. type c:\data\2-texts.cs>c:\数据\文件1\001\data\2-texts.cs   
  5. type c:\data\3-texts.cs>c:\数据\文件1\001\data\3-texts.cs  
  6. type c:\data\4-texts.cs>c:\数据\文件1\001\data\4-texts.cs  
  7. type c:\data\5-texts.cs>c:\数据\文件1\001\data\5-texts.cs  
  8. type c:\data\6-texts.cs>c:\数据\文件1\001\data\6-texts.cs  
  9. type c:\data\7-texts.cs>c:\数据\文件1\001\data\7-texts.cs
  10. type c:\data\8-texts.cs>c:\数据\文件1\001\data\8-texts.cs  
  11. type c:\data\9-texts.cs>c:\数据\文件1\001\data\9-texts.cs  
  12. type c:\data\10-texts.cs>c:\数据\文件1\001\data\10-texts.cs
  13. type c:\data\11-texts.cs>c:\数据\文件1\001\data\11-texts.cs
  14. type c:\data\12-texts.cs>c:\数据\文件1\001\data\12-texts.cs  
  15. type c:\data\13-texts.cs>c:\数据\文件1\001\data\13-texts.cs
  16. type c:\data\14-texts.cs>c:\数据\文件1\001\data\14-texts.cs
  17. type c:\data\15-texts.cs>c:\数据\文件1\001\data\15-texts.cs
  18. type c:\data\16-texts.cs>c:\数据\文件1\001\data\16-texts.cs
  19. type c:\data\17-texts.cs>c:\数据\文件1\001\data\17-texts.cs
  20. type c:\data\18-texts.cs>c:\数据\文件1\001\data\18-texts.cs
  21. type c:\data\19-texts.cs>c:\数据\文件1\001\data\19-texts.cs
  22. type c:\data\20-texts.cs>c:\数据\文件1\001\data\20-texts.cs
  23. type c:\data\21-texts.cs>c:\数据\文件1\001\data\21-texts.cs
  24. type c:\data\22-texts.cs>c:\数据\文件1\001\data\22-texts.cs
  25. type c:\data\23-texts.cs>c:\数据\文件1\001\data\23-texts.cs
  26. type c:\data\24-texts.cs>c:\数据\文件1\001\data\24-texts.cs
  27. type c:\data\2011ALD-qc.txt>c:\数据\文件1\001\data\2011ALD-qc.txt
  28. exit
复制代码
1

评分人数

    • Batcher: 感谢给帖子标题标注[已解决]字样PB + 2

  1. @echo off
  2. for /f "delims=" %%a in ('dir /ad /b /s "C:\数据\data"') do (
  3.     rd /s /q "%%a"
  4.     xcopy /s /h /y "C:\data\*" "%%~dpa\data\"
  5. )
  6. pause
复制代码
1

评分人数

TOP

xcopy /s /h /y "C:\data\*" "%%~dpa\data" 可以简化成 xcopy /s /h /y "C:\data" "%%~dpa\",不过效率应该差不多...
1

评分人数

TOP

返回列表