Board logo

标题: [文本处理] [已解决]批处理如何批量分割文本文件? [打印本页]

作者: ysrr2011    时间: 2015-3-8 16:09     标题: [已解决]批处理如何批量分割文本文件?

  1. @echo off
  2. cd /d "D:\XSS"
  3. set file="+Q5.1.txt"
  4. set per=50
  5. for %%a in (%file%) do set "dpn=%%~dpna" & set "x=%%~xa"
  6. set /a count=per-1, n=0
  7. setlocal enabledelayedexpansion
  8. for /f "usebackq delims=" %%a in (!file!) do (
  9.   set /a count+=1, n=count/per
  10.   echo %%a>>"D:\SS\!n!.+Q5.1!x!"
  11. )
  12. EXIT
复制代码
以上代码对1个指定文件进行分割处理,输出为序号+原文件名。请问如何修改,可对一个文件夹所有文件进行相同分割处理?
作者: pcl_test    时间: 2015-3-8 16:32

回复 1# ysrr2011
  1. @echo off
  2. setlocal enabledelayedexpansion
  3. cd /d "D:\XSS"
  4. for %%a in (*.txt) do (
  5. set per=50
  6. set /a count=per-1, n=0
  7. for /f "delims=" %%b in ('type "%%a"') do (
  8. set /a count+=1, n=count/per
  9. if not exist "D:\SS\%%~na\" md "D:\SS\%%~na\"
  10. echo %%b>>"D:\SS\%%~na\!n!.%%~nxa"
  11. )
  12. )
  13. EXIT
复制代码





欢迎光临 批处理之家 (http://www.bathome.net/) Powered by Discuz! 7.2