标题: [文件操作] 批处理运行越久越慢怎么办? [打印本页]
作者: 857185187 时间: 2020-10-13 18:07 标题: 批处理运行越久越慢怎么办?
开始运行的时候速度还可以,随着运行时间越久就越慢
看任务管理器显示,内存占用一直在稳定增加,好像CMD不会自动释放内存
有办法解决么?
作者: Batcher 时间: 2020-10-13 23:37
回复 1# 857185187
请把完整代码发出来看下如何优化
作者: peterboy666 时间: 2020-10-14 02:27
以前遇过读取文件
1 到 N 列 越读越慢
最后写小程序解决
作者: 857185187 时间: 2020-10-14 18:33
回复 2# Batcher - @echo off
- Setlocal EnableDelayedExpansion
- set "LOGFILE=%~dpn0.LOG"
-
- Echo !date:~0,10! !time! --START CreateSHA1>>"!LOGFILE!"
- certutil /? 1>nul 2>nul
- if errorlevel 1 goto :exit
- wmic /? 1>nul 2>nul
- if errorlevel 1 goto :exit
-
- For /r "D:\" %%a in (*.*) do (
- set fail=1
- echo %%a
- set "currentfilename=%%a"
- set "SIZE=%%~za"
- set "NXNAME=%%~nxa"
- Call :Process
- )
-
- Echo !date:~0,10! !time! --END CreateSHA1>>"!LOGFILE!"
-
- exit /b
- :Process
- Call :GetSHA1
- if fail==0 exit /b
- Call :GetVersion
- Call :CreateFile
-
- exit /b
- :GetSHA1
- set SHA1=
- set "InFile=!currentfilename!"
- For /F "skip=1 delims=" %%b in ('certutil -hashfile "!InFile!" SHA1') do (
- set "SHA1=%%b"
- if "!SHA1:~0,8!"=="CertUtil" Call :OutputLog GetSHA1 1 "!SHA1:CertUtil:=!" & exit /b
- set "SHA1=!SHA1: =!"
- ECHO SHA1:!SHA1!
- Exit /b
- )
-
- EXIT /B
- :GetVersion
- set filename=!currentfilename:\=\\!
- For /F "skip=1 delims=" %%c in ('wmic datafile where "name='!filename!'" get version') do (
- set "Version=%%c"
- if not "!Version:~0,1!"==" " (
- echo Ver:!Version!
- exit /b
- ) else (
- rem echo GetVersion Failed
- exit /b
- )
- )
-
- EXIT /B
- :CreateFile
- echo !NXNAME! Ver:!Version! SIZE:!SIZE! SHA1:!SHA1! >>%~dp0!NXNAME!.SHA1
- if not exist "%~dp0!NXNAME!.SHA1" Call :OutputLog CreateFile 1
- for %%z in ("%~dp0!NXNAME!.SHA1") do ( if %%~zz==0 Call :OutputLog CreateFile 1 "Invalid Data" & exit /b)
-
- exit /b
- :OutputLog
- set PARAMETERS=
- set PARAMETERS=%*
- if "!PARAMETERS!"=="" echo !date:~0,10! !time! --!currentfilename! OutputLog Failed No Parameters >>"!LOGFILE!" & exit /b
- if !errorlevel!==0 (
- set Fail=1
- if %1==Rename Echo !date:~0,10! !time! --!currentfilename! Rename to !filesrename! Succeeded>>"!LOGFILE!"
- if %1==Decompression Echo !date:~0,10! !time! --!currentfilename! Decompression Succeeded>>"!LOGFILE!"
- ) else (
- set Fail=0
- if %1==Rename Echo !date:~0,10! !time! --!currentfilename! Rename to !filesrename! Failed ErrorCode=!errorlevel!>>"!LOGFILE!"
- if %1==Decompression Echo !date:~0,10! !time! --!currentfilename! Decompression Failed ErrorCode=!errorlevel!>>"!LOGFILE!"
- )
- if "%2"=="0" (
- set Fail=1
- if %1==Getdate Echo !date:~0,10! !time! --!currentfilename! Get File Time Succeeded>>"!LOGFILE!"
- )
- if "%2"=="1" (
- set Fail=0
- if %1==Getdate Echo !date:~0,10! !time! --!currentfilename! Get File Time Failed %~3>>"!LOGFILE!"
- if %1==CreateFile Echo !date:~0,10! !time! --!currentfilename! CreateFile Failed %~3>>"!LOGFILE!"
- if %1==GetSHA1 Echo !date:~0,10! !time! --!currentfilename! GetSHA1 Failed %~3>>"!LOGFILE!"
- )
-
- exit /b
- :Exit
- echo Fatal error,try to change the platform,press any key to exit his program
- pause >nul
- exit /b
复制代码
作者: Batcher 时间: 2020-10-14 18:44
回复 4# 857185187
请参考Q-01观察一下在哪一步花费的时间比较长:
https://mp.weixin.qq.com/s/6lbb97qUOs1sTyKJfN0ZEQ
欢迎光临 批处理之家 (http://bbs.bathome.net/) |
Powered by Discuz! 7.2 |