找回密码
 注册
搜索
[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
查看: 23207|回复: 4

[文本处理] 批处理如何将100组数据平均分成10个记事本格式?

[复制链接]
发表于 2012-11-5 21:54:58 | 显示全部楼层 |阅读模式
记事本D.TXT 含有100组数据
如何将100组数据按顺序平均分成10个记事本格式

每个记事本含有10组数据(去除标点符号) 每行1组数据 共10行

先谢谢各位朋友了
发表于 2012-11-6 00:39:01 | 显示全部楼层
  1. @echo off&setlocal enabledelayedexpansion
  2. set /a n=0,m=1
  3. for /f "delims=" %%a in (d.txt) do (
  4.   for %%b in (%%a) do (
  5.     set /a n+=1
  6.     echo %%b>>!m!.txt
  7.     if "!n!"=="10" set /a n=0,m+=1
  8.   )
  9. )
  10. pause
复制代码
是不是这样?
发表于 2012-11-6 05:04:24 | 显示全部楼层
本帖最后由 wc726842270 于 2012-11-6 05:06 编辑

唉,写了个VBS,没有什么通用性,想要实到的话,代码怎么也得80行左右,上火

  1. Set fso=CreateObject("scripting.filesystemobject")
  2. If fso.fileexists("e:\a.txt") Then
  3. Set ofile=fso.OpenTextFile("e:\a.txt",1)
  4. Else
  5. wscript.echo "the file is not exists"
  6. WScript.Quit(1)
  7. End If
  8. str=ofile.readall
  9. arr=Split(str,vbCrLf)
  10. nfile=UBound(arr)/10+1
  11. nnum=0
  12. For i=1 To nfile
  13.         If Not fso.FileExists(i&".txt") Then
  14.         Set newfile=fso.OpenTextFile(i&".txt",2,True)
  15.         Else
  16.         WScript.Echo i&".txt file is exists"
  17.         WScript.Quit(2)
  18.         End If
  19.         number=0
  20.         For n=nnum To uBound(arr)
  21.         number=number+1
  22.         If (ofile.AtEndOfStream And number<>10) Then
  23.         newfile.WriteLine arr(n)
  24.         Else
  25.         Exit for
  26.         End If
  27.         Next
  28.         nnum=i*10
  29.         newfile.Close
  30.         Set newfile=nothing
  31. Next
  32. ofile.Close
  33. Set fso=Nothing
复制代码
PS:只是玩一下,练习而以
发表于 2012-11-6 09:11:50 | 显示全部楼层
唉,写了个VBS,没有什么通用性,想要实到的话,代码怎么也得80行左右,上火PS:只是玩一下,练习而以
wc726842270 发表于 2012-11-6 05:04



    注意缩进。
发表于 2012-11-6 09:42:17 | 显示全部楼层
了解

  1. Set fso=CreateObject("scripting.filesystemobject")
  2. If fso.fileexists("e:\a.txt") Then
  3.         Set ofile=fso.OpenTextFile("e:\a.txt",1)
  4. Else
  5.         wscript.echo "the file is not exists"
  6.         WScript.Quit(1)
  7. End If
  8. str=ofile.readall
  9. arr=Split(str,vbCrLf)
  10. nfile=UBound(arr)/10+1 '此处有点问题,最好用MOD来判断一下,要不如果是10的倍数的话,可能会多创建一个文件。不过在此就不改了
  11. nnum=0
  12. For i=1 To nfile
  13.         If Not fso.FileExists(i&".txt") Then
  14.                 Set newfile=fso.OpenTextFile(i&".txt",2,True)
  15.         Else
  16.                 WScript.Echo i&".txt file is exists"
  17.                 WScript.Quit(2)
  18.         End If
  19.         number=0
  20.         For n=nnum To uBound(arr)
  21.                 number=number+1
  22.                 If (number<>10 and ofile.AtEndOfStream) Then
  23.                         newfile.WriteLine arr(n)
  24.                 Else
  25.                         Exit for
  26.                 End If
  27.         Next
  28.         nnum=i*10
  29.         newfile.Close
  30.         Set newfile=nothing
  31. Next
  32. ofile.Close
  33. Set fso=Nothing
复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|批处理之家 ( 渝ICP备10000708号 )

GMT+8, 2026-3-20 02:26 , Processed in 0.018517 second(s), 8 queries , File On.

Powered by Discuz! X3.5

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表