Board logo

标题: [文件操作] 批处理如何获取文件的大小? [打印本页]

作者: romandec    时间: 2008-8-19 09:44     标题: 批处理如何获取文件的大小?

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!
作者: romandec    时间: 2008-8-19 10:00

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

新手发帖,请大家多多赐教,谢谢了
作者: romandec    时间: 2008-8-19 10:06

我错了,版主帮忙改到“代码讨论”区吧,谢谢
作者: pusofalse    时间: 2008-8-19 12:35

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
复制代码

作者: romandec    时间: 2008-8-20 09:36

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

dos下的比较大小用哪个命令?
大家帮忙看看啊!!!
作者: pusofalse    时间: 2008-8-20 10:19

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
复制代码





欢迎光临 批处理之家 (http://bbs.bathome.net/) Powered by Discuz! 7.2