中国DOS联盟论坛

中国DOS联盟

-- 联合DOS 推动DOS 发展DOS --

联盟域名:www.cn-dos.net  论坛域名:www.cn-dos.net/forum
DOS,代表着自由开放与发展,我们努力起来,学习FreeDOS和Linux的自由开放与GNU精神,共同创造和发展美好的自由与GNU GPL世界吧!

游客:  注册 | 登录 | 命令行 | 会员 | 搜索 | 上传 | 帮助 »
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » 【共享】文件 网络 系统 批函数若干
« [1] [2] »
作者:
标题: 【共享】文件 网络 系统 批函数若干 上一主题 | 下一主题
plp626
银牌会员

钻石会员


积分 2278
发帖 1020
注册 2007-11-19
状态 离线
『楼 主』:  【共享】文件 网络 系统 批函数若干

英文不行的就算了。。。。

【转】

  Quote:
File and Directory Functions

2 楼       FileSizeComp

  3       GetDirStats

4        IsDirEmpty

5        IsInPath
Network Functions

6         GetDG

7        GetIP

8         GetMAC

9        GetNA

10         GetSM
System Functions

11         GetOS

12        IsRunning

13        Sleep

14      Timer

15  楼   Uptime

附加:16楼     Reading Files

[ Last edited by plp626 on 2008-4-27 at 04:02 AM ]



山外有山,人外有人;低调做人,努力做事。

进入网盘(各种工具)~~ 空间~~cmd学习
2008-4-27 02:59
查看资料  发短消息 网志   编辑帖子  回复  引用回复
plp626
银牌会员

钻石会员


积分 2278
发帖 1020
注册 2007-11-19
状态 离线
『第 2 楼』:  

FileSizeComp

The FileSizeComp function compares the size of a specified file.

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:FileSizeComp %file% %operand% %size%
::
:: By:   Ritchie Lawrence, 2003-08-22. Version 1.0
::
:: Func: Compares size of specified file against specified size using
::       specified operand. Errorlevel set to zero if result is true, and
::       set to 1 if false or -1 if file not found. For NT4/2000/XP/2003.
::
:: Args: %1 File to compare (by val)
::       %2 Comparison operator <EQU | NEQ | LSS | LEQ | GTR | GEQ> (by val)
::       %3 Size to compare in bytes (by val)
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
setlocal ENABLEEXTENSIONS & set "filter=2^>nul^|findstr/b /v /c:" ""
for /f "tokens=3" %%a in ('dir/-c %1 %filter%') do set z=%%a 0000000000000
if not defined z (endlocal & fc;: 2>nul & goto :EOF) else (set z=%z:~0,13%)
set "c=%3 0000000000000" & call set "c=%%c:~0,13%%"
for /f "tokens=1-4" %%a in ("%z% %c%") do set "z=%%b%%a" & set "c=%%d%%c"
(md;2>nul & if "%z%" %2 "%c%" ver>nul) & (endlocal & goto:EOF)
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::  

Parameters

%1 File to compare (by val)
%2 Comparison operator <EQU | NEQ | LSS | LEQ | GTR | GEQ> (by val)
%3 Size to compare in bytes (by val)

Return Values

See parameters above.

Example

@echo off & setlocal ENABLEEXTENSIONS
call :FileSizeComp c:\logs\backup.log GTR 1048576 || goto :EOF
echo/c:\logs\backup.log is larger than 1MB
goto :EOF

Remarks

The comparison operator (parameter 2) must be uppercase otherwise the function will fail under Windows NT 4.0. If a non Windows NT 4.0 solution is required, it is more efficient to use the enhanced parameter modifiers present in Windows 2000 and later. For example:-

@echo off & setlocal ENABLEEXTENSIONS
for %%a in (c:\logs\backup.log) do if %%~za LEQ 1048576 goto :EOF
echo/c:\logs\backup.log is larger than 1MB
goto :EOF



山外有山,人外有人;低调做人,努力做事。

进入网盘(各种工具)~~ 空间~~cmd学习
2008-4-27 03:00
查看资料  发短消息 网志   编辑帖子  回复  引用回复
plp626
银牌会员

钻石会员


积分 2278
发帖 1020
注册 2007-11-19
状态 离线
『第 3 楼』:  

GetDirStats

The GetDirStats function returns the number of files, subdirectories and total size of a specified directory.

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:GetDirStats %dir% files dirs bytes
::
:: By:   Ritchie Lawrence, updated 2003-09-18. Version 1.1
::
:: Func: Returns total number of files, directories and bytes (includes
::       sub-directories and hidden/system files/dirs). For NT4/2000/XP/2003
::
:: Args: %1 Name of directory, absolute or relative (by val)
::       %2 var to receive total number of files (by ref)
::       %3 var to receive total number of directories (by ref)
::       %4 var to receive total number of bytes (by ref)
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
setlocal ENABLEEXTENSIONS & set "var="
pushd %1 2>nul || (md;2>nul & endlocal & goto :EOF)
for /f "tokens=1-5* delims=," %%a in ('compact/s /q^|findstr ^^^^[0-O]') ^
do (call set "var=%%var%% %%a%%b%%c%%d%%e")
for /f "tokens=2,5,15" %%a in ('echo/%var%') do (popd & endlocal ^
  & set "%4=%%c" & set/a %3=%%b-1 & set/a "%2=%%a-%%b+1" & goto :EOF)
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::  

Parameters

%1 Name of directory, absolute or relative (by val)
%2 var to receive total number of files (by ref)
%3 var to receive total number of directories (by ref)
%4 var to receive total number of bytes (by ref)

Return Values

If the function succeeds, the errorlevel is set to zero. If the function fails (for example, due to invalid directory or insufficient permissions), then the errorlevel is set to one.

Example

@echo off & setlocal ENABLEEXTENSIONS
call :GetDirStats %SystemRoot% f d b
echo/%SystemRoot% has %f% files and %d% dirs. Total size is %b% bytes .
goto :EOF

Remarks

The statistics returned by GetDirStats are identical to those returned by Windows Explorer. If a difference is observed, this is probably caused by the TEMP folder being included in the enumeration.



山外有山,人外有人;低调做人,努力做事。

进入网盘(各种工具)~~ 空间~~cmd学习
2008-4-27 03:00
查看资料  发短消息 网志   编辑帖子  回复  引用回复
plp626
银牌会员

钻石会员


积分 2278
发帖 1020
注册 2007-11-19
状态 离线
『第 4 楼』:  

IsDirEmpty

The IsDirEmpty function determines if the specified directory is empty.

:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:IsDirEmpty %dir%
::
:: By:   Ritchie Lawrence, 2003-09-22. Version 1.0
::
:: Func: If specified directory is empty of files and directories, then
::       errorlevel is set to zero. If directory is not empty or does not
::       exist, errorlevel is non-zero one. For NT4/2000/XP/2003.
::
:: Args: %1 Name of directory to be tested (by val)
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
setlocal ENABLEEXTENSIONS & dir/ad %1 >nul 2>nul || (endlocal & goto :EOF)
set i=0 & for /f %%a in ('dir %1/a/b 2^>nul') do set/a "i+=1"
md;2>nul & (if %i%==0 ver>nul) & endlocal & goto :EOF
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  

Parameters

%1 Name of directory to be tested (by val)

Return Values

If specified directory does not contain any files (including SYSTEM and/or HIDDEN files) and the specified directory does not contain any subdirectories, the errorlevel is set to zero. If the specified directory in not empty or does not exist, the errorlevel is set to non-zero

Example

@echo off & setlocal ENABLEEXTENSIONS
set var="c:\test dir"
call :IsDirEmpty %var% && echo/%var% is empty
goto :EOF

Remarks

None.



山外有山,人外有人;低调做人,努力做事。

进入网盘(各种工具)~~ 空间~~cmd学习
2008-4-27 03:00
查看资料  发短消息 网志   编辑帖子  回复  引用回复
plp626
银牌会员

钻石会员


积分 2278
发帖 1020
注册 2007-11-19
状态 离线
『第 5 楼』:  

IsInPath

The IsInPath function determines if the specified files are in the current directory or in a directory listed in the path statement.

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:IsInPath %filelist%
::
:: By:   Ritchie Lawrence, 2003-11-29. Version 1.0
::
:: Func: Checks if the file(s) in the specified list exist within the
::       current directory or path. If all files found, errorlevel set to
::       zero otherwise non-zero. NT4/2000/XP/2003.
::
:: Args: %1 List of files separated by whitespace (by val)
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
setlocal ENABLEEXTENSIONS & set "path=.;%path%" & set "i="
for %%a in (%*) do for %%b in (%%a) do if not exist "%%~$PATH:b" set "i=1"
ver>nul & if defined i md;2>nul & endlocal & goto:EOF
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::  

Parameters

%1 List of files separated by whitespace (by val)

Return Values

See parameters above.

Example

@echo off & setlocal ENABLEEXTENSIONS
set "tools="
set "tools=%tools% ping.exe"
set "tools=%tools% find.exe"
set "tools=%tools% "exe with space in name.exe""
set "tools=%tools% drivers\etc\hosts"

call :IsInPath %tools% || (
  >&2echo/Error: Unable to locate the utilities required by this script.
  md;2>nul & goto :EOF
)

rem Rest of code here...
goto :EOF

Remarks

A space, a tab and a semi-colon are considered to be whitespace.



山外有山,人外有人;低调做人,努力做事。

进入网盘(各种工具)~~ 空间~~cmd学习
2008-4-27 03:01
查看资料  发短消息 网志   编辑帖子  回复  引用回复
plp626
银牌会员

钻石会员


积分 2278
发帖 1020
注册 2007-11-19
状态 离线
『第 6 楼』:  

GetDG

The GetDG function returns the default gateway.

:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:GetDG dg
::
:: By:   Ritchie Lawrence, 2003-09-22. Version 1.0
::
:: Func: Obtains the default gateway. For NT4/2000/XP/2003.
::       If functions fails, 0.0.0.0 is returned.
::
:: Args: %1 var to receive default gateway (by ref)
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
setlocal ENABLEEXTENSIONS & set "g=0.0.0.0" & set "j="
for /f "tokens=3" %%a in ('route print^|findstr 0.0.0.0.*0.0.0.0') do (
  if not defined j for %%b in (%%a) do set "g=%%b" & set "j=1")
endlocal & set "%1=%g%" & goto :EOF
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::  

Parameters

%1 var to receive default gateway (by ref)

Return Values

See parameters above.

Example

@echo off & setlocal ENABLEEXTENSIONS
call :GetDG dg
echo/Default Gateway is: %dg%
goto :EOF

Remarks

If the machine has more than one interface, the default gateway returned will be that of the interface whose IP address is attached to the default route.



山外有山,人外有人;低调做人,努力做事。

进入网盘(各种工具)~~ 空间~~cmd学习
2008-4-27 03:01
查看资料  发短消息 网志   编辑帖子  回复  引用回复
plp626
银牌会员

钻石会员


积分 2278
发帖 1020
注册 2007-11-19
状态 离线
『第 7 楼』:  

GetIP

The GetIP function returns the IP address of the primary adapter.

:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:GetIP ip
::
:: By:   Ritchie Lawrence, 2003-09-22. Version 1.0
::
:: Func: Obtains the IP address of primary adapter. For NT4/2000/XP/2003.
::       If functions fails, 0.0.0.0 is returned.
::
:: Args: %1 var to receive IP address (by ref)
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
setlocal ENABLEEXTENSIONS & set "i=0.0.0.0" & set "j="
for /f "tokens=4" %%a in ('route print^|findstr 0.0.0.0.*0.0.0.0') do (
  if not defined j for %%b in (%%a) do set "i=%%b" & set "j=1")
endlocal & set "%1=%i%" & goto :EOF
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::  

Parameters

%1 var to receive IP Address (by ref)

Return Values

See parameters above.

Example

@echo off & setlocal ENABLEEXTENSIONS
call :GetIP ip
echo/IP Address is: %ip%
goto :EOF

Remarks

If the machine has more than one interface, the IP address returned will be that of the interface whose IP address is attached to the default route.



山外有山,人外有人;低调做人,努力做事。

进入网盘(各种工具)~~ 空间~~cmd学习
2008-4-27 03:02
查看资料  发短消息 网志   编辑帖子  回复  引用回复
plp626
银牌会员

钻石会员


积分 2278
发帖 1020
注册 2007-11-19
状态 离线
『第 8 楼』:  

GetMAC

The GetMAC function returns the MAC address of the primary adapter.

:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:GetMAC mac
::
:: By:   Ritchie Lawrence, 2003-09-24. Version 1.0
::
:: Func: Obtains the MAC address of the primary adapter in the format of
::       XX-XX-XX-XX-XX-XX. If the function fails 00-00-00-00-00-00 is
::       returned. For NT4/2000/XP/2003.
::
:: Args: %1 var to receive MAC address (by ref)
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
setlocal ENABLEEXTENSIONS & set "m=00-00-00-00-00-00" & set "i=" & set "j="
set "n=0" & set "c=ipconfig/all" & set "f=findstr"
for /f "tokens=4" %%a in ('route print^|findstr 0.0.0.0.*0.0.0.0') do (
  if not defined j for %%b in (%%a) do set "i=%%b" & set "j=1") & set "j="
if not defined i endlocal & set "%1=%m%" & goto :EOF
for /f "delims=:" %%a in ('%c%^|%f%/n IP.Address.*%i%') do set /a n=%%a-6
for /f "delims=" %%a in ('%c%^|more/e +%n%^|%f% Physical.Address') do (
  if not defined j for %%b in (%%a) do set "m=%%b" & set "j=1")
endlocal & set "%1=%m%" & goto :EOF
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::  

Parameters

%1 var to receive MAC address (by ref)

Return Values

See parameters above.

Example

@echo off & setlocal ENABLEEXTENSIONS
call :GetMAC mac
echo/MAC address is: %mac%
goto :EOF

Remarks

To remove the dashes from the result use variable substitution. For example:-



山外有山,人外有人;低调做人,努力做事。

进入网盘(各种工具)~~ 空间~~cmd学习
2008-4-27 03:02
查看资料  发短消息 网志   编辑帖子  回复  引用回复
plp626
银牌会员

钻石会员


积分 2278
发帖 1020
注册 2007-11-19
状态 离线
『第 9 楼』:  

GetNA

The GetNA function returns the network address of the primary adapter.

:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:GetNA na
::
:: By:   Ritchie Lawrence, 2003-09-22. Version 1.0
::
:: Func: Obtains network address of primary adapter. For NT4/2000/XP/2003.
::       If functions fails, 0.0.0.0 is returned.
::
:: Args: %1 var to receive network address (by ref)
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
setlocal ENABLEEXTENSIONS & set "i=0.0.0.0" & set "n=0.0.0.0" & set "j="
for /f "tokens=4" %%a in ('route print^|findstr 0.0.0.0.*0.0.0.0') do (
if not defined j (for %%b in (%%a) do set "i=%%b" & set j=1)) & set "k="
for /f "skip=1 tokens=1,3-4" %%a in ('route print^|findstr/b /c:" "') do (
  for %%e in (%%a) do set "x=%%e" & for %%f in (%%b) do set "y=%%f"
  for %%g in (%%c) do set "z=%%g"
  for /f "tokens=1-3" %%a in ('echo/%%x%% %%y%% %%z%%') do (
    if not defined k if "%%c"=="%i%" if "%%b"=="%i%" set k=1 & set n=%%a))
endlocal & set "%1=%n%" & goto :EOF
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::  

Parameters

%1 var to receive network address (by ref)

Return Values

See parameters above.

Example

@echo off & setlocal ENABLEEXTENSIONS
call :GetNA na
echo/Network address: %na%
goto :EOF

Remarks

If the machine has more than one interface, the network address returned will be that of the interface whose IP address is attached to the default route.

Note the third, fourth and fifth FOR loops strip whitespace for compatability with NT4.0 without using a TAB character in the script.



山外有山,人外有人;低调做人,努力做事。

进入网盘(各种工具)~~ 空间~~cmd学习
2008-4-27 03:02
查看资料  发短消息 网志   编辑帖子  回复  引用回复
plp626
银牌会员

钻石会员


积分 2278
发帖 1020
注册 2007-11-19
状态 离线
『第 10 楼』:  

GetSM

The GetSM function returns the subnet mask of the primary adapter.

:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:GetSM sm
::
:: By:   Ritchie Lawrence, 2003-09-22. Version 1.0
::
:: Func: Obtains the subnet mask of primary adapter. For NT4/2000/XP/2003.
::       If functions fails, 0.0.0.0 is returned.
::
:: Args: %1 var to receive subnet mask (by ref)
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
setlocal ENABLEEXTENSIONS & set "i=0.0.0.0" & set "m=0.0.0.0" & set "j="
for /f "tokens=4" %%a in ('route print^|findstr 0.0.0.0.*0.0.0.0') do (
  if not defined j (for %%b in (%%a) do set "i=%%b" & set j=1)) & set "k="
for /f "skip=1 tokens=2-4" %%a in ('route print^|findstr/b /c:" "') do (
  for %%e in (%%a) do set "x=%%e" & for %%f in (%%b) do set "y=%%f"
  for %%g in (%%c) do set "z=%%g"
  for /f "tokens=1-3" %%a in ('echo/%%x%% %%y%% %%z%%') do (
    if not defined k if "%%c"=="%i%" if "%%b"=="%i%" set k=1 & set m=%%a))
endlocal & set "%1=%m%" & goto :EOF
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::  

Parameters

%1 var to receive subnet mask (by ref)

Return Values

See parameters above.

Example

@echo off & setlocal ENABLEEXTENSIONS
call :GetSM sm
echo/Subnet Mask is: %sm%
goto :EOF

Remarks

If the machine has more than one interface, the subnet mask returned will be that of the interface whose IP address is attached to the default route.

Note the third, fourth and fifth FOR loops strip whitespace for compatability with NT4.0 without using a TAB character in the script.



山外有山,人外有人;低调做人,努力做事。

进入网盘(各种工具)~~ 空间~~cmd学习
2008-4-27 03:02
查看资料  发短消息 网志   编辑帖子  回复  引用回复
plp626
银牌会员

钻石会员


积分 2278
发帖 1020
注册 2007-11-19
状态 离线
『第 11 楼』:  

GetOS

The GetOS function returns the operating system version.

:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:GetOS os
::
:: By:   Ritchie Lawrence, 2003-09-18. Version 1.0
::
:: Func: Returns the O/S version; NT40, 2000, 2002 or 2003.
::       For NT4/2000/XP/2003.
::
:: Args: %1 var to receive O/S version (by ref)
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
setlocal ENABLEEXTENSIONS & set "cmd=net config work^|findstr/b /c:"Soft""
for /f "tokens=1-2 delims=." %%a in ('%cmd%') do (
  for %%z in (%%a%%b) do set o=%%z)
endlocal & set "%1=%o:40=NT40%" & (goto :EOF)
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::  

Parameters

%1 var to receive O/S version (by ref)

Return Values

Value Operating System
NT40 Microsoft Windows NT 4.0
2000 Microsoft Windows 2000
2002 Microsoft Windows XP
2003 Microsoft Windows 2003

Example

@echo off & setlocal ENABLEEXTENSIONS
call :GetOS ver
echo/Operating System is: %ver%
goto :EOF

Remarks

This function is independant of the command interpreter version, i.e. If the script is executed by a Windows 2000 version of cmd.exe on a Windows NT 4.0 machine, NT40 will be returned.



山外有山,人外有人;低调做人,努力做事。

进入网盘(各种工具)~~ 空间~~cmd学习
2008-4-27 03:03
查看资料  发短消息 网志   编辑帖子  回复  引用回复
plp626
银牌会员

钻石会员


积分 2278
发帖 1020
注册 2007-11-19
状态 离线
『第 12 楼』:  

IsRunning

The IsRunning function determines if the specified service is running.

:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:IsRunning %svc%
::
:: By:   Ritchie Lawrence, 2003-10-08. Version 1.0
::
:: Func: Sets errorlevel to zero if the specified service is running,
::       otherwise errorlevel set to one. For NT4/2000/XP/2003.
::
:: Args: %1 Display name of the service to check (by val)
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
setlocal ENABLEEXTENSIONS & set "svc=%1"
set svc=%svc:"=%
net start | findstr/i /b /e /c:"   %svc%" >nul
endlocal & goto :EOF
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::  

Parameters

%1 Display name of the service to check (by val)

Return Values

See parameters above.

Example

@echo off & setlocal ENABLEEXTENSIONS
call :IsRunning "Task Scheduler" && echo/Yes || echo/No
goto :EOF

Remarks

Note that Findstr is used with the /b and /e switches to avoid false positives. This could happen when checking if "Server" service is running and there are other services containing the word "server". Also note there are three spaces between /c:" and %svc%".

Bear in mind that a paused service is still regarded as running by the net command. If it's important to know whether the service is running and not paused, then a third party utility will be required for Windows NT4 and 2000. Windows XP and 2003 can use the built-in SC.exe tool.



山外有山,人外有人;低调做人,努力做事。

进入网盘(各种工具)~~ 空间~~cmd学习
2008-4-27 03:03
查看资料  发短消息 网志   编辑帖子  回复  引用回复
plp626
银牌会员

钻石会员


积分 2278
发帖 1020
注册 2007-11-19
状态 离线
『第 13 楼』:  

Sleep

The Sleep function suspends execution of the current batch file for a specified interval.

:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:Sleep %secs%
::
:: By:   Ritchie Lawrence, 2003-09-16. Version 1.0
::
:: Func: Suspends batch execution for a number of seconds.
::       For NT4/2000/XP/2003.
::
:: Args: %1 Number of seconds to wait for (by val)
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
setlocal ENABLEEXTENSIONS & set /a n=%1+1
ping -n %n% 127.0.0.1 >nul
endlocal & goto :EOF
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::  

Parameters

%1 Number of seconds to wait for (by val)

Return Values

See parameters above.

Example

@echo off
call :Sleep 5
goto :EOF

Remarks

This function is based on the idea by Clay Calvert.



山外有山,人外有人;低调做人,努力做事。

进入网盘(各种工具)~~ 空间~~cmd学习
2008-4-27 03:03
查看资料  发短消息 网志   编辑帖子  回复  引用回复
plp626
银牌会员

钻石会员


积分 2278
发帖 1020
注册 2007-11-19
状态 离线
『第 14 楼』:  

Timer

The Timer function returns the number of elapsed seconds since the function was last called and first called.

:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:Timer ID
::
:: By:   Ritchie Lawrence, 2002-10-10. Version 1.1
:: Updated 2007-10-31 - thanks to Fabricio and Darren
::
:: Func: Returns number of seconds elapsed since the function was last
::       called and first called. For NT4/2000/XP/2003.
::
:: Args: %1 (by ref) The first time this function is called, this variable
::       is initialised to '<last> <first> <init>' where <last> and <first>
::       are zero and <init> is the number of elapsed seconds since
::       1970-01-01 00:00:00. This value is used by subsequent calls to
::       determine the elapsed number of seconds since the last call
::       (<last>) and the first call (<first>).
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
setlocal ENABLEEXTENSIONS&call set ID=%%%1%%
set t=2&if "%date%z" LSS "A" set t=1
for /f "skip=1 tokens=2-4 delims=(-)" %%a in ('echo/^|date') do (
  for /f "tokens=%t%-4 delims=.-/ " %%d in ('date/t') do (
    set %%a=%%d&set %%b=%%e&set %%c=%%f))
for /f "tokens=5-7 delims=:. " %%a in ('echo/^|time') do (
  set hh=%%a&set nn=%%b&set ss=%%c)
set /a dd=100%dd%%%100,mm=100%mm%%%100
set /a z=14-mm,z/=12,y=yy+4800-z,m=mm+12*z-3,j=153*m+2
set /a j=j/5+dd+y*365+y/4-y/100+y/400-2472633
set /a hh=100%hh%%%100,nn=100%nn%%%100,ss=100%ss%%%100
set /a j=j*86400+hh*3600+nn*60+ss
for /f "tokens=1-3 delims= " %%a in ('echo/%ID%') do (
  set l=%%a&set f=%%b&set c=%%c)
if {%c%}=={} endlocal&set %1=0 0 %j%&goto :EOF
set /a l=j-c-f,f+=l
endlocal&set %1=%l% %f% %c%&goto :EOF
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  

Parameters

%1 (by ref) The first time this function is called, this variable is initialised to '<last> <first> <init>' where <last> and <first> are zero and <init> is the number of elapsed seconds since 1970-01-01 00:00:00. This value is used by subsequent calls to determine the elapsed number of seconds since the last call (<last>) and the first call (<first>).

Return Values

See parameters above.

Example

@echo off & setlocal
set var=
call :Timer var
call :show

::wait about 3 seconds
ping 127.0.0.1 -n 4 >nul
call :Timer var
call :show

::wait about 7 seconds
ping 127.0.0.1 -n 8 >nul
call :Timer var
call :show
goto :EOF

:show
for /f "tokens=1-2 delims= " %%a in ('echo/%var%') do (
  echo/Seconds since last call: %%a, seconds since first call: %%b
)
goto :EOF

Remarks

The first time the function is called, it should be passed an undefined variable.

Multiple timers can be used in parallel; just use a different variable name for each instance. See the function's header for more information.

Update: Corrected an error in the penultimate statement (it used to read: set /a l=j-c-l,f+=l) - thank you Fabricio and Darren for spotting this error.



山外有山,人外有人;低调做人,努力做事。

进入网盘(各种工具)~~ 空间~~cmd学习
2008-4-27 03:03
查看资料  发短消息 网志   编辑帖子  回复  引用回复
plp626
银牌会员

钻石会员


积分 2278
发帖 1020
注册 2007-11-19
状态 离线
『第 15 楼』:  

Uptime

The Uptime function returns the elapsed days, hours, minutes and seconds since the system booted.

:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:Uptime days hours mins [secs]
::
:: By:   Ritchie Lawrence, 2003-09-24. Version 1.0
::
:: Func: Obtains the number of days, hours, minutes and seconds of uptime.
::       For NT4/2000/XP/2003.
::
:: Args: %1 var to receive number of days of uptime (by ref)
::       %2 var to receive number of hours of uptime (by ref)
::       %3 var to receive number of minutes of uptime (by ref)
::       %4 var to receive number of seconds of uptime (optional, by ref)
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
setlocal ENABLEEXTENSIONS & set "c=net statistics work"
set t=2&if "%date%z" LSS "A" set t=1
for /f "skip=1 tokens=2-4 delims=(-)" %%a in ('echo/^|date') do (
  for /f "tokens=%t%-4 delims=.-/ " %%d in ('date/t') do (
    set %%a=%%d&set %%b=%%e&set %%c=%%f))
for /f "tokens=5-8 delims=:. " %%a in ('echo/^|time') do (
  set "hh=%%a" & set "nn=%%b" & set "ss=%%c")
if 1%yy% LSS 200 if 1%yy% LSS 170 (set yy=20%yy%) else (set yy=19%yy%)
set /a dd=100%dd%%%100,mm=100%mm%%%100
set /a z=14-mm,z/=12,y=yy+4800-z,m=mm+12*z-3,j=153*m+2
set /a j=j/5+dd+y*365+y/4-y/100+y/400-2472633
if 1%hh% LSS 20 set hh=0%hh%
set /a hh=100%hh%%%100,nn=100%nn%%%100,f=j*1440+hh*60+nn
for /f "tokens=3-8 delims=/:M " %%a in ('%c%^|findstr/b /c:"Stat"') do (
  set mm=%%a&set dd=%%b&set yy=%%c&set hh=%%d&set nn=%%e%%f)
if 1%yy% LSS 200 if 1%yy% LSS 170 (set yy=20%yy%) else (set yy=19%yy%)
set /a dd=100%dd%%%100,mm=100%mm%%%100
set /a z=14-mm,z/=12,y=yy+4800-z,m=mm+12*z-3,j=153*m+2
set /a j=j/5+dd+y*365+y/4-y/100+y/400-2472633
if 1%hh% LSS 20 set hh=0%hh%
if {%nn:~2,1%} EQU {P} if "%hh%" NEQ "12" set hh=1%hh%&set/a hh-=88
if {%nn:~2,1%} EQU {A} if "%hh%" EQU "12" set hh=00
if {%nn:~2,1%} GEQ {A} set nn=%nn:~0,2%
set /a hh=100%hh%%%100,nn=100%nn%%%100,s=j*1440+hh*60+nn,n=f-s
set /a d=n/1440,n%%=1440,h=n/60,n%%=60
endlocal & set "%1=%d%" & set "%2=%h%" & set "%3=%n%" ^
  & (if "%4" NEQ "" set "%4=%ss%") & goto :EOF
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::  

Parameters

%1 var to receive number of days of uptime (by ref)
%2 var to receive number of hours of uptime (by ref)
%3 var to receive number of minutes of uptime (by ref)
%4 var to receive number of seconds of uptime (optional, by ref)

Return Values

See parameters above.

Example

@echo off & setlocal ENABLEEXTENSIONS
call :Uptime d h n s
echo/Uptime is: %d% days, %h% hours, %n% minutes, %s% seconds.
goto :EOF

Remarks

The uptime reported by this function is typically less than +/- 30 seconds of the uptime reported by third party utilities such as SrvInfo from the Resource Kit and PsInfo from sysinternals.



山外有山,人外有人;低调做人,努力做事。

进入网盘(各种工具)~~ 空间~~cmd学习
2008-4-27 03:04
查看资料  发短消息 网志   编辑帖子  回复  引用回复
« [1] [2] »
请注意:您目前尚未注册或登录,请您注册登录以使用论坛的各项功能,例如发表和回复帖子等。


可打印版本 | 推荐给朋友 | 订阅主题 | 收藏主题



论坛跳转: