[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

[文件操作] 批处理如何获取文件的大小?

for /f "Tokens=1-4 Delims=/ " %%i in ('date /t') do  set dt=%%i-%%j-%%k-%%l
for /f "Tokens=1-2" %%i in ('time /t') do set tm=-%%i-%%j
set tm=%tm::=-%
set dtt=%dt%%tm%
set app=App%dtt%
set sec=Sec%dtt%
set odiag=Odiag%dtt%
set osess=OSess%dtt%
set sys=Sys%dtt%
cd\
c:
cd %windir%\system32\config
copy app*.evt d:\sysbak\app
copy sec*.evt d:\sysbak\sec
copy odi*.evt d:\sysbak\odiag
copy ose*.evt d:\sysbak\osess
copy sys*.evt d:\sysbak\sys
d:\sysbak\sleep  6
cd\
d:
cd sysbak
if exist app\AppEvent.Evt ren app\AppEvent.evt %app%.Evt
if exist sec\SecEvent.Evt ren sec\SecEvent.Evt %sec%.Evt
if exist odiag\ODiag.Evt ren odiag\ODiag.Evt %odiag%.Evt
if exist osess\OSession.Evt ren osess\OSession.Evt %osess%.Evt
if exist sys\SysEvent.Evt ren sys\SysEvent.Evt %sys%.Evt
smtpsend [email=-ftest3@test.COM.CN]-ftest3@test.COM.CN[/email] [email=-Txxx@test.com.cn]-Txxx@test.com.cn[/email] -hxxex01 -s %dtt% Server XXX backup Success!

在server上用上面的批处理+计划任务实现了自动备份
还想实现判断日志大小的功能,当大小超过5M,通知管理员或者是做其它处理
但是不知道在dos下如何判断文件大小,希望高手指点一下

新手发帖,请大家多多赐教,谢谢了

TOP

我错了,版主帮忙改到“代码讨论”区吧,谢谢

TOP

for %%a in (a.txt) do echo %%~za
显示a.txt的大小。
  1. %~I         - expands %I removing any surrounding quotes (")
  2. %~fI        - expands %I to a fully qualified path name
  3. %~dI        - expands %I to a drive letter only
  4. %~pI        - expands %I to a path only
  5. %~nI        - expands %I to a file name only
  6. %~xI        - expands %I to a file extension only
  7. %~sI        - expanded path contains short names only
  8. %~aI        - expands %I to file attributes of file
  9. %~tI        - expands %I to date/time of file
  10. %~zI        - expands %I to size of file
  11. %~$PATH:I   - searches the directories listed in the PATH
  12.                environment variable and expands %I to the
  13.                fully qualified name of the first one found.
  14.                If the environment variable name is not
  15.                defined or the file is not found by the
  16.                search, then this modifier expands to the
  17.                empty string
复制代码
心绪平和,眼藏静谧。

TOP

感谢版主回复,不过还是不清楚怎样比较大小啊
我想实现的功能是:
if SecEvent.Evt>5M  do 备份&清空安全日至
或者是
if SecEvent.Evt>5M  do 备份&提示管理员

dos下的比较大小用哪个命令?
大家帮忙看看啊!!!

TOP

if/?
  1. where compare-op may be one of:
  2.     EQU - equal
  3.     NEQ - not equal
  4.     LSS - less than
  5.     LEQ - less than or equal
  6.     GTR - greater than
  7.     GEQ - greater than or equal
复制代码
心绪平和,眼藏静谧。

TOP

返回列表