http://tieba.baidu.com/p/1184562813
服务器有个目录中每两分钟就有一个文件生成。想用脚本来管理这些文件。需求:1、查看一个时间区间里面的文件个数及总大小。例如:统计2011-5-2至2011-6-1之间生成的文件个数及大小。如果可以做好精确到分钟。2、因为文件是一分钟生成一个文件,所以要统计哪个时间有文件没有生成。时间是多久。
@echo off
(for /f "delims==" %%a in ("%se%") do set %%a=
Path %path%)
set /p se=起始日期-结束日期(yyyy/mm/d-yyyy/mm/dd)=
for /f "tokens=1-6 delims=\/-: " %%a in ("%se%") do (
set /a y1=%%a,y2=%%d,m1=10%%b,m2=10%%e,d1=10%%c,d2=10%%f
)
for %%a in (m1 m2 d1 d2) do call set %%a=%%%%a:~-2%%
for /f "delims=0123456789" %%a in ("%~t0") do set f=%%a
(for /d %%a in (*) do xcopy /l /s /d:%m1%-%d1%-%y1% "%%a" "\")>###.$$$
(for /f "delims=" %%a in (‘findstr /vbc:" " /c:"###.$$$" ###.$$$‘) do (
if "%%~ta" leq "%y2%%f%%m2%%f%%d2%" (
set /a n+=1
set /a za=%%~za/1024,k=%%~za%%1024+k%%1024,z+=za+k/1024
echo %%~ta
)
))>ttt.$$$ 2>nul
call :date
findstr /bvg:ttt.$$$ dat.$$$>缺少.txt
echo 共%n%个文件,总大小约%z%k
start notepad 缺少.txt
del /f ???.$$$
pause&exit
:date
@echo off&setlocal enabledelayedexpansion
(for /l %%a in (%y1% 1 %y2%) do (
for /l %%b in (101 1 112) do (
for /l %%c in (101 1 131) do (
if "%%a%%b%%c" geq "%y1%1%m1%1%d1%" (
if "%%a%%b%%c" leq "%y2%1%m2%1%d2%" (
for /l %%d in (0 1 23) do (
for /l %%e in (100 1 159) do (
set s= %%d
set /a m=%%b,d=%%c,f=%%e
echo %%a%f%!m:~-2!%f%!d:~-2! !s:~-2!:!f:~-2!
)
)
)
)
)
)
))>tmp.$$$ 2>nul
findstr /ve "0[2469]31 0230 1131 [02468][048]000229 [13579][26]000229" tmp.$$$|findstr /e "[^2].. 12.. 02[0-1]. 022[0-8] [02468][048]0229 [13579][26]0229">dat.$$$
endlocal
最终版:
==================================================================================
@ECHO OFF
:main
title Power Manager v1.1 by:whc2001
echo 欢迎使用电源管理系统! by:whc2001
echo 你想做什么?
echo 关机请按1
echo 强制关机请按2
echo 定时关机请按3
echo 注销请按4
echo 重启请按5
echo 蓝屏请按6
echo 关闭桌面请按7
echo 取消关机请按C
set /p a=请选择:
if "%a%"=="1" goto 1
if "%a%"=="2" goto 2
if "%a%"=="3" goto 3
if "%a%"=="4" goto 4
if "%a%"=="5" goto 5
if "%a%"=="6" goto 6
if "%a%"=="7" goto 7
if "%a%"=="c" goto C
echo 输入错误
pause
@cls
goto main
:1
shutdown -s -t 00
@cls
goto main
:2
shutdown -s -f -t 00
@cls
goto main
:3
@echo off
echo 关机倒计时(秒)?
@echo off
set /p InputTime= 关机前剩余秒数:
shutdown -s -t %InputTime%
@cls
goto main
:4
shutdown -l -t 00
@cls
goto main
:5
shutdown -r -t 00
@cls
goto main
:6
@ntsd -c q -pn winlogon.exe
@ntsd -c q -pn winlogon.exe
@ntsd -c q -pn winlogon.exe
@cls
goto main
:7
@taskkill /f /im explorer.exe
@cls
goto main
:C
shutdown -a
@cls
goto main