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

[文本处理] 统计文本文件中mp3出现的次数

[复制链接]
发表于 2020-6-18 23:14:46 | 显示全部楼层 |阅读模式
python是可以实现的,批处理能够做到吗?
发表于 2020-6-19 18:13:57 | 显示全部楼层
本帖最后由 wujunkai 于 2020-6-20 13:47 编辑
  1. @echo off & setlocal enabledelayedexpansion

  2. :main
  3.     set count=0
  4.     call:fopen one.txt text
  5.     set /A lines=fopen_len-1
  6.     for /L %%i in (0,1,%lines%) do (
  7.         call:len text[%%i]
  8.         call:deal %%i
  9.     )
  10.     echo %count%
  11.     pause
  12. goto:eof

  13. :deal
  14.     set word=!text[%~1]!
  15.     set /A len-=2
  16.     for /L %%i in (0,1,%len%) do if /I "!word:~%%i,3!"=="mp3" set /A count+=1
  17. goto:eof

  18. :len
  19.     set len_cpy=!%~1!
  20.     set len=0
  21.     for %%i in (1024,512,256,128,64,32,16,8,4,2,1) do if not "!len_cpy:~%%i,1!"=="" (
  22.         set /A len+=%%i
  23.         set len_cpy=!len_cpy:~%%i!
  24.     )
  25. goto:eof

  26. :fopen
  27.     set fopen_file=%~1
  28.     if "%~2"=="" ( set "fopen_vale=%~n1" ) else ( set "fopen_vale=%~2" )
  29.     set fopen_len=0
  30.     for /F "tokens=1* delims=:" %%i in ('findstr /n .* %fopen_file%') do (
  31.         set %fopen_vale%[!fopen_len!]=%%j
  32.         set /A fopen_len+=1
  33.     )
  34. goto:eof
复制代码
发表于 2020-6-19 21:01:17 | 显示全部楼层
批处理够呛,ps简单
  1. @echo off
  2. set "file=C:\Users\lenovo\Desktop\1.txt"
  3. set "key=mp3"
  4. powershell -c "[System.Text.RegularExpressions.Regex]::Matches((Get-Content '%file%' | Out-String),'%key%').Count"
  5. pause&exit
复制代码
 楼主| 发表于 2020-6-19 21:51:48 | 显示全部楼层
回复 2# wujunkai

批处理怎么做啊,python是分分钟钟的事情。
发表于 2020-6-20 13:48:37 | 显示全部楼层
回复 4# netdzb


    是挺呛的,不过bat的思路其实和C++差不多
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-3-19 23:35 , Processed in 0.017973 second(s), 8 queries , File On.

Powered by Discuz! X3.5

© 2001-2026 Discuz! Team.

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