回复 12# shelluserwlb
优化第一步:- @echo off
- set "n=0"
- set "dri=c d e f g h i j k l m n o p q r s t u v w x y z"
- if exist mp3flie.txt del mp3flie.txt
-
- echo 正在查找mp3文件,请稍候...
- for %%i in (%dri%) do (
- if exist %%i: call :1 %%i
- )
- echo 全盘mp3总数量为:%n%
- pause
- goto :eof
-
- :1
- REM 把重定向放到for循环外面可以提高代码执行效率
- (for /r %1: %%a in ("*.mp3") do (
- set /a n+=1
- echo %%a
- ))>>mp3flie.txt
- goto :eof
复制代码 优化第二步:- @echo off
- set "n=0"
- set "dri=c d e f g h i j k l m n o p q r s t u v w x y z"
- REM 由于在最外层for循环外面做重定向,下面这个判断可以省略
- REM if exist mp3flie.txt del mp3flie.txt
-
- echo 正在查找mp3文件,请稍候...
- REM 把重定向尽可能的往外移
- (for %%i in (%dri%) do (
- if exist %%i: call :1 %%i
- ))>mp3flie.txt
- echo 全盘mp3总数量为:%n%
- pause
- goto :eof
-
- :1
- for /r %1: %%a in ("*.mp3") do (
- set /a n+=1
- echo %%a
- )
- goto :eof
复制代码 优化第三步:- @echo off
- set "n=0"
- set "dri=c d e f g h i j k l m n o p q r s t u v w x y z"
- REM 由于在最外层for循环外面做重定向,下面这个判断可以省略
- REM if exist mp3flie.txt del mp3flie.txt
-
- echo 正在查找mp3文件,请稍候...
- REM 把重定向尽可能的往外移
- (for %%i in (%dri%) do (
- if exist %%i: call :1 %%i
- ))>mp3flie.txt
-
- for /f %%i in ('type mp3flie.txt^|find /c /v ""') do (
- set "RowNum=%%i"
- )
- echo,%RowNum%
- echo 全盘mp3总数量为:%RowNum%
- pause
- goto :eof
-
- :1
- for /r %1: %%a in ("*.mp3") do (
- REM 假设总共有十万个mp3文件,那么就要做十万次计算,可以把它拿到for循环外面去
- REM set /a n+=1
- echo %%a
- )
- goto :eof
复制代码
|