标题: [其他] 【已解决】批处理type中,循环语句如何表示? [打印本页]
作者: 思想之翼 时间: 2024-9-11 09:33 标题: 【已解决】批处理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
上述代码标红处,如何正确表示?
作者: qixiaobin0715 时间: 2024-9-11 09:58
- @echo off
- setlocal enabledelayedexpansion
- md "D:\DATA2" 2>nul
- cd /d "D:\DATA"
- for /l %%i in (1,2,499) do (
- set /a m+=1
- set /a n=%%i+1
- type "%%i.txt" "!n!.txt" 2>nul>"D:\DATA2\!m!.txt"
- )
- pause
复制代码
作者: aloha20200628 时间: 2024-9-11 10:53
本帖最后由 aloha20200628 于 2024-9-11 10:59 编辑
回复 1# 思想之翼 - @echo off &setlocal enabledelayedexpansion
- for /l %%n in (1,1,250) do (
- set/a "n2=2*%%n,n1=n2-1"
- type "d:\data\!n1!.txt" "d:\data\!n2!.txt">"d:\data2\%%n.txt"
- ) 2>nul
- endlocal&pause&exit/b
复制代码
作者: 77七 时间: 2024-9-11 12:23
- @echo off
- cd /d "d:\data"
- setlocal enabledelayedexpansion
- for /l %%l in (1,2,500) do (
- set /a n=%%l+1,m+=1
- > "d:\data2\!m!.txt" (
- find /v "" < "%%l.txt"
- find /v "" < "!n!.txt"
- )
- )
- endlocal
- pause
复制代码
欢迎光临 批处理之家 (http://bbs.bathome.net/) |
Powered by Discuz! 7.2 |