使用Windows批处理文件测量打开大文件的时间

时间:2015-05-04 17:56:00

标签: windows file batch-file

我想使用Windows批处理文件打开几个大文件(word,excel,power-point等),我想记录操作是否通过。如果它通过我想写入日志。我所做的一切都在下面,但是,我无法衡量打开文件所需的时间。我尝试了几个脚本,但都失败了。

请你帮帮我

echo StartTime = %Time% >> C:\Users\abc\Desktop\time.log
start winword.exe && (
echo Pass: MS Word opened at: %date% %time% >> C:\Users\abc\Desktop\time.log
) || (
echo Fail: MS Word Errored at: %date% %time% >> C:\Users\abc\Desktop\time.log
)
echo EndTime = %Time% >> C:\Users\abc\Desktop\time.log


echo StartTime = %Time% >> C:\Users\abc\Desktop\time.log
start excel.exe && (
echo Pass: MS Excel opened at: %date% %time% >> C:\Users\abc\Desktop\time.log
) || (
echo Fail: MS Excel Errored at: %date% %time% >> C:\Users\abc\Desktop\time.log
)
echo EndTime = %Time% >> C:\Users\abc\Desktop\time.log

1 个答案:

答案 0 :(得分:0)

这里的bat文件返回自1970年上次访问文件(lastaccessed.bat)以来传递的毫秒数,该文件采用单个参数 - 文件:

@if (@x)==(@y) @end /***** jscript comment ******
     @echo off
     cscript //E:JScript //nologo "%~f0"  %* 
     exit /b %errorlevel%

 @if (@x)==(@y) @end ******  end comment *********/

var FileSystemObj = new ActiveXObject("Scripting.FileSystemObject");

var ARGS = WScript.Arguments;
var filename=ARGS.Item(0);
var FileSystemObj = new ActiveXObject("Scripting.FileSystemObject");
function getLastAccessed(obj){
    return obj.DateLastAccessed;
}

var file=FileSystemObj.GetFile(filename);
WScript.Echo((new Date(file.DateLastAccessed)).getTime());

这里是dbenham的jeval.bat

@if (@X)==(@Y) @end /* harmless hybrid line that begins a JScrpt comment

::************ Documentation ***********
:::
:::jEval  JScriptExpression  [/N]
:::jEval  /?
:::
:::  Evaluates a JScript expression and writes the result to stdout.
:::
:::  A newline (CR/LF) is not appended to the result unless the /N
:::  option is used.
:::
:::  The JScript expression should be enclosed in double quotes.
:::
:::  JScript string literals within the expression should be enclosed
:::  in single quotes.
:::
:::  Example:
:::
:::    call jEval "'5/4 = ' + 5/4"
:::
:::  Output:
:::
:::    5/4 = 1.25
:::

::************ Batch portion ***********
@echo off

if "%~1" equ "" (
  call :err "Insufficient arguments"
  exit /b
)
if "%~2" neq "" if /i "%~2" neq "/N" (
  call :err "Invalid option"
  exit /b
)
if "%~1" equ "/?" (
  setlocal enableDelayedExpansion
  for /f "delims=" %%A in ('findstr "^:::" "%~f0"') do (
    set "ln=%%A"
    echo(!ln:~3!
  )
  exit /b
)
cscript //E:JScript //nologo "%~f0" %*
exit /b

:err
>&2 echo ERROR: %~1. Use jeval /? to get help.
exit /b 1


************ JScript portion ***********/
if (WScript.Arguments.Named.Exists("n")) {
  WScript.StdOut.WriteLine(eval(WScript.Arguments.Unnamed(0)));
} else {
  WScript.StdOut.Write(eval(WScript.Arguments.Unnamed(0)));
}

以下是如何计算文件两个开口之间的传递时间(以秒为单位):

@echo off
for /f %%a in ('lastaccessed.bat "c:\My Folder\book1.xlsx"') do set "time1=%%a"
excel.exe  "c:\My Folder\book1.xlsx"
for /f %%a in ('lastaccessed.bat "c:\My Folder\book1.xlsx"') do set "time2=%%a"

call jeval.bat "(%time2% - %time1%)/1000"

这是你要找的吗?