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

[其他] 【已解决】批处理type中,循环语句如何表示?

D:\DATA\文件夹中有500个文本,分别命名为1.txt 2.txt...500.txt

欲1.txt 与 2.txt合并,3.txt 与 4.txt合并......499.txt 与 500.txt合并

type D:\DATA\1.txt > D:\DATA2\1.txt
type D:\DATA\2.txt >> D:\DATA2\1.txt

type D:\DATA\3.txt > D:\DATA2\2.txt
type D:\DATA\4.txt >> D:\DATA2\2.txt
......
type D:\DATA\499.txt > D:\DATA2\250.txt
type D:\DATA\500.txt >> D:\DATA2\250.txt

@echo off
setlocal enabledelayedexpansion
for /l %%f in (1,1,250) do (
    set q=%%f
    type D:\DATA\!q!*2-1.txt > D:\DATA2\!q!.txt
    type D:\DATA\!q!*2.txt >> D:\DATA2\!q!.txt
)
endlocal
exit

上述代码标红处,如何正确表示?
1

评分人数

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

  1. @echo off
  2. setlocal enabledelayedexpansion
  3. md "D:\DATA2" 2>nul
  4. cd /d "D:\DATA"
  5. for /l %%i in (1,2,499) do (
  6.     set /a m+=1
  7.     set /a n=%%i+1
  8.     type "%%i.txt" "!n!.txt" 2>nul>"D:\DATA2\!m!.txt"
  9. )
  10. pause
复制代码
1

评分人数

TOP

本帖最后由 aloha20200628 于 2024-9-11 10:59 编辑

回复 1# 思想之翼
  1. @echo off &setlocal enabledelayedexpansion
  2. for /l %%n in (1,1,250) do (
  3. set/a "n2=2*%%n,n1=n2-1"
  4. type "d:\data\!n1!.txt" "d:\data\!n2!.txt">"d:\data2\%%n.txt"
  5. ) 2>nul
  6. endlocal&pause&exit/b
复制代码
1

评分人数

TOP

  1. @echo off
  2. cd /d "d:\data"
  3. setlocal enabledelayedexpansion
  4. for /l %%l in (1,2,500) do (
  5. set /a n=%%l+1,m+=1
  6. > "d:\data2\!m!.txt" (
  7. find /v "" < "%%l.txt"
  8. find /v "" < "!n!.txt"
  9. )
  10. )
  11. endlocal
  12. pause
复制代码
bat小白,请多指教!谢谢!

TOP

返回列表