标题: [文件操作] 批处理如何获取文件的大小? [打印本页]
作者: 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的大小。
-
- %~I - expands %I removing any surrounding quotes (")
- %~fI - expands %I to a fully qualified path name
- %~dI - expands %I to a drive letter only
- %~pI - expands %I to a path only
- %~nI - expands %I to a file name only
- %~xI - expands %I to a file extension only
- %~sI - expanded path contains short names only
- %~aI - expands %I to file attributes of file
- %~tI - expands %I to date/time of file
- %~zI - expands %I to size of file
- %~$PATH:I - searches the directories listed in the PATH
- environment variable and expands %I to the
- fully qualified name of the first one found.
- If the environment variable name is not
- defined or the file is not found by the
- search, then this modifier expands to the
- 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/?- where compare-op may be one of:
-
- EQU - equal
- NEQ - not equal
- LSS - less than
- LEQ - less than or equal
- GTR - greater than
- GEQ - greater than or equal
复制代码
欢迎光临 批处理之家 (http://bathome.net./) |
Powered by Discuz! 7.2 |