本帖最后由 wankoilz 于 2013-9-1 13:28 编辑
最近空时间多,来凑个热闹,希望能拿个第三名吧!
所有代码在win7下测试通过。
有什么问题还望Batcher指点。
帖子代码的显示稍微窄了点儿,长一点的句子显示出来不整齐。
总共才300kb,结果附件不能大于50kb,不得不压缩成7个包... ...
1、- @echo off
- call :rd ".\测试文件夹"&exit
-
- :rd
- for /f "delims=" %%a in ('dir/a-d/b %1 2^>nul') do if not "%%a"=="" del "%~1\%%a" /f
- for /f "delims=" %%a in ('dir/ad/b %1 2^>nul') do if not "%%a"=="" call :rd "%~1\%%a"
- rd %1 /q 2>nul
复制代码 2、- @echo off
- for /f "skip=4 delims=" %%i in ('net user') do (
- if not "%%i"=="命令成功完成。" (
- (for %%j in (%%i) do echo %%j)>User_List.txt
- ))
- (findstr /v /g:User_List.txt DBatHome_User_List.txt)>Gone_Users.txt
- (findstr /v /g:DBatHome_User_List.txt User_List.txt)>New_Users.txt
复制代码 3、- @echo off
- set str=abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789~!@#$%%^^^&*+
- setlocal enabledelayedexpansion
- for /l %%a in (1001,1,1100) do (
- call :get_rnd
- set password=%%a!rnd!
- set username=%%a&set username=!username:~1!&set username=BatHome!username!
- echo net user !username! !password! /add
- )
- pause&exit
-
- :get_rnd 生成四位带一个大写、一个小写字母、一个数字、一个特殊字符的不重复字符串
- set rnd=
- set /a l=!random!%%26,u=!random!%%26+26,n=!random!%%10+52,t=!random!%%10+62
- for %%a in (!l!,!u!,!n!,!t!) do (
- set rnd=!rnd!!str:~%%a,1!
- )
- if not defined !rnd! (set !rnd!=yes
- ) else (call :get_rnd)
复制代码 4、- @echo off&title DateToSecs函数 BY Batcher Else BY wankoilz
- set "len=for /f "tokens=1-2" %%1 in ("$") do (set ##=!%%1!&set %%2=&(for %%a in (4096,2048,1024,512,256,128,64,32,16,8,4,2,1) do (if not "!%%1:~%%a,1!"=="" (set/a %%2+=%%a&set %%1=!%%1:~%%a!)))&(if not "!%%1!"=="" set/a %%2+=1)&set %%1=!##!)"
- setlocal enabledelayedexpansion
- echo MemoryInfo:
- call :Show_MemoryInfo
- echo;&echo DiskInfo(Wait a moment):
- call :Show_DiskInfo
- echo;&echo SystemRunningTimeDiff:
- call :Show_SystemRunningTimeDiff
- echo;&pause&goto :eof
-
- :Show_MemoryInfo
- for %%a in (物理内存总量 可用的物理内存) do (
- set /a n+=1
- for /f "tokens=2" %%b in ('systeminfo ^| findstr "%%a"') do (
- set mem!n!=%%b
- )
- )
- set rest=!mem2:^,=!&set total=!mem1:^,=!
- set/a used=!total!-!rest!
- set used=!used!0000
- set/a percent=!used!/!total!
- set percent=0000!percent!
- set percent_int=!percent:~0,-2!&set percent_float=!percent:~-2!
- call :trim percent_int !percent_int!
- set percent=!percent_int!.!percent_float!%
- set total=!total!0000
- set/a total=!total!/1024
- set total=0000!total!
- set int_total=!total:~0,-4!&set float_total=!total:~-4!
- call :trim int_total !int_total!
- set total_GB=!int_total!.!float_total!
- echo 总内存:!total_GB!GB
- echo 内存使用率:!percent!
- goto :eof
-
- :Show_DiskInfo
- for /f "skip=1 tokens=1-3" %%a in ('wmic logicaldisk get name^,size^,freespace') do (
- if not "%%c"=="" (
- set quotient=&call :division %%c 1073741824
- set size=!quotient! GB
- set quotient=&call :division %%a %%c
- set quotient=!quotient:^.=!&set quotient=!quotient:~0,5!
- call :trim quotient !quotient!
- set/a used_per=10000-!quotient!
- set used_per=0000!used_per!&set used_per=!used_per:~-4!
- set used_per_int=!used_per:~0,2!&set used_per_float=!used_per:~2!
- call :trim used_per_int !used_per_int!
- set used_per=!used_per_int!.!used_per_float!
- for /l %%a in (1,1,13) do set size= !size!
- echo %%b盘容量!size:~-13! 使用率!used_per!%
- )
- )
- goto :eof
-
-
- :Show_SystemRunningTimeDiff
- for /f "tokens=2-3" %%a in ('net statistics workstation^|findstr "统计数据开始于"') do (
- set StartTime=%%a %%b
- )
- for /f "tokens=1" %%a in ("%date%") do set date=%%a
- set EndTime=%date% %time:~0,-3%
- echo 最近一次开机时间:%starttime%
- echo 当前时间:%endtime%
- call :DateDiff %StartTime% %EndTime%
- echo 系统已运行时间:%Y%年%D%日%H%时%M%分%S%秒
- goto :eof
-
- :DateDiff !StartTime! !EndTime!
- set StartTime=%StartTime:-= %
- set StartTime=%StartTime:/= %
- set StartTime=%StartTime::= %
- set EndTime=%EndTime:-= %
- set EndTime=%EndTime:/= %
- set EndTime=%EndTime::= %
- call :DateToSecs %StartTime% StartSecs
- call :DateToSecs %EndTime% EndSecs
- set /a DiffSecs=EndSecs-StartSecs
- set DiffSecs=%DiffSecs:-= %
- set /a Y=DiffSecs/31536000
- set /a D=(DiffSecs%%31536000)/86400
- set /a H=(DiffSecs%%86400)/3600
- set /a M=(DiffSecs%%3600)/60
- set /a S=DiffSecs%%60
- goto :eof
-
- :DateToSecs %yy% %mm% %dd% %hh% %nn% %ss% secs
- setlocal ENABLEEXTENSIONS
- set yy=%1&set mm=%2&set dd=%3&set hh=%4&set nn=%5&set ss=%6
- 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,ss=100%ss%%%100
- set /a j=j*86400+hh*3600+nn*60+ss
- endlocal&set %7=%j%&goto :eof
-
-
- :division
- setlocal
- set dividend=%1&set divisor=%2
- %len:$=dividend length_dividend%
- %len:$=divisor length_divisor%
- set add=4
- for /l %%a in (1,1,!add!) do set dividend=!dividend!0
- set/a length_dividend+=!add!
- set/a up=!length_dividend!-1
- for /l %%a in (0,1,!up!) do (
- set minuend=!minuend!!dividend:~%%a,1!
- call :trim minuend !minuend!
- call :compare !minuend! !divisor!
- if "!flag_com!"=="geq" (
- set quo=&call :subtraction !minuend! !divisor!
- set quotient=!quotient!!quo!
- set minuend=!D_value!
- ) else (
- set quotient=!quotient!0
- )
- )
- set int=!quotient:~0,-%add%!&set float=!quotient:~-%add%!
- call :trim int !int!
- set quotient=!int!.!float!
- endlocal&set quotient=%quotient%&goto :eof
-
-
- :subtraction 被减数 减数
- setlocal&set a=%1&set b=%2&set/a quo+=1
- %len:$=a length_a%
- set b=0!b!&set b=!b:~-%length_a%!
- set/a p=!length_a!-1
- for /l %%a in (0,1,!p!) do (
- set arrA_%%a=!a:~%%a,1!
- set arrB_%%a=!b:~%%a,1!
- )
- for /l %%a in (!p!,-1,0) do (
- if !arrA_%%a! geq !arrB_%%a! (
- set/a dif=!arrA_%%a!-!arrB_%%a!&set diff=!dif!!diff!
- ) else (
- set/a borrow=%%a-1
- set/a arrA_!borrow!-=1
- set/a dif=!arrA_%%a!+10-!arrB_%%a!
- set diff=!dif!!diff!
- )
- )
- if "!diff:~0,1!"=="0" call :trim diff !diff!
- call :compare !diff! %2
- if "!flag_com!"=="geq" (
- endlocal&set quo=%quo%&set diffr=%diff%&call :subtraction !diffr! %2
- ) else (
- endlocal&set quo=%quo%&set D_value=%diff%&goto :eof
- )
-
-
- :compare 被减数 减数(除数)
- setlocal&set a=%1&set b=%2
- %len:$=a length_a%
- %len:$=b length_b%
- set/a l=!length_a!-1
- if !length_a! gtr !length_b! (endlocal&set flag_com=geq&goto :eof)
- if !length_a! lss !length_b! (endlocal&set flag_com=lss&goto :eof)
- if !length_a! equ !length_b! (
- if "!a!"=="!b!" (
- endlocal&set flag_com=geq&goto :eof
- ) else (
- for /l %%a in (0,1,!l!) do (
- if "!a:~%%a,1!" gtr "!b:~%%a,1!" (endlocal&set flag_com=geq&goto :eof)
- if "!a:~%%a,1!" lss "!b:~%%a,1!" (endlocal&set flag_com=lss&goto :eof)
- )
- )
- )
-
- :trim
- setlocal
- set a=%2
- if "!a:~0,1!"=="0" (if not "!a!"=="0" (endlocal&set %1=%a:~1%&call :trim %1 !%1!))
复制代码 5、- @echo off
- Rem 增量备份就是加了个/d
- if "%date:~-2%"=="周日" (
- xcopy /e/h/r/y/k/o/f/exclude:filter.txt "D:\www.bathome" "D:\bbs.bathome"
- ) else (
- xcopy /e/h/r/y/k/o/f/d/exclude:filter.txt "D:\www.bathome" "D:\bbs.bathome"
- )
- pause>nul
复制代码 6、- @echo off&Rem 因为精确位数很容易修改,所以最后一位没有进行四舍五入
- set "len=for /f "tokens=1-2" %%1 in ("$") do (set ##=!%%1!&set %%2=&(for %%a in (4096,2048,1024,512,256,128,64,32,16,8,4,2,1) do (if not "!%%1:~%%a,1!"=="" (set/a %%2+=%%a&set %%1=!%%1:~%%a!)))&(if not "!%%1!"=="" set/a %%2+=1)&set %%1=!##!)"
- setlocal enabledelayedexpansion&title 任意位正整数除法 BY wankoilz
- set/p x=输入被除数:
- set/p y=输入除数:
- echo 计算中...
- call :division !x! !y!
- cls&echo 被除数:!x!&echo 除数:!y!&echo 商:!quotient!
- echo;&pause&exit
-
- :division
- setlocal
- set dividend=%1&set divisor=%2
- %len:$=dividend length_dividend%
- %len:$=divisor length_divisor%
- set add=100
- for /l %%a in (1,1,!add!) do set dividend=!dividend!0
- set/a length_dividend+=!add!
- set/a up=!length_dividend!-1
- for /l %%a in (0,1,!up!) do (
- set/p=^><nul
- set minuend=!minuend!!dividend:~%%a,1!
- call :trim minuend !minuend!
- call :compare !minuend! !divisor!
- if "!flag_com!"=="geq" (
- set quo=&call :subtraction !minuend! !divisor!
- set quotient=!quotient!!quo!
- set minuend=!D_value!
- ) else (
- set quotient=!quotient!0
- )
- )
- set int=!quotient:~0,-%add%!&set float=!quotient:~-%add%!
- call :trim int !int!
- set quotient=!int!.!float!
- endlocal&set quotient=%quotient%&goto :eof
-
-
- :subtraction 被减数 减数
- setlocal&set a=%1&set b=%2&set/a quo+=1
- %len:$=a length_a%
- set b=0!b!&set b=!b:~-%length_a%!
- set/a p=!length_a!-1
- for /l %%a in (0,1,!p!) do (
- set arrA_%%a=!a:~%%a,1!
- set arrB_%%a=!b:~%%a,1!
- )
- for /l %%a in (!p!,-1,0) do (
- if !arrA_%%a! geq !arrB_%%a! (
- set/a dif=!arrA_%%a!-!arrB_%%a!&set diff=!dif!!diff!
- ) else (
- set/a borrow=%%a-1
- set/a arrA_!borrow!-=1
- set/a dif=!arrA_%%a!+10-!arrB_%%a!
- set diff=!dif!!diff!
- )
- )
- if "!diff:~0,1!"=="0" call :trim diff !diff!
- call :compare !diff! %2
- if "!flag_com!"=="geq" (
- endlocal&set quo=%quo%&set diffr=%diff%&call :subtraction !diffr! %2
- ) else (
- endlocal&set quo=%quo%&set D_value=%diff%&goto :eof
- )
-
-
- :compare 被减数 减数(除数)
- setlocal&set a=%1&set b=%2
- %len:$=a length_a%
- %len:$=b length_b%
- set/a l=!length_a!-1
- if !length_a! gtr !length_b! (endlocal&set flag_com=geq&goto :eof)
- if !length_a! lss !length_b! (endlocal&set flag_com=lss&goto :eof)
- if !length_a! equ !length_b! (
- if "!a!"=="!b!" (
- endlocal&set flag_com=geq&goto :eof
- ) else (
- for /l %%a in (0,1,!l!) do (
- if "!a:~%%a,1!" gtr "!b:~%%a,1!" (endlocal&set flag_com=geq&goto :eof)
- if "!a:~%%a,1!" lss "!b:~%%a,1!" (endlocal&set flag_com=lss&goto :eof)
- )
- )
- )
-
- :trim
- setlocal
- set a=%2
- if "!a:~0,1!"=="0" (if not "!a!"=="0" (endlocal&set %1=%a:~1%&call :trim %1 !%1!))
复制代码 7、- @echo off&setlocal enabledelayedexpansion
- set/p url=请输入系列壁纸的网址:
- Rem wget http://www.zhuoku.com/zhuomianbizhi/star-starcn/20130729110511.htm
- wget !url!
- set Lf=^
-
-
- for %%a in ("!url!") do (set filename=%%~nxa&set dirname=%%~na)
- md !dirname! 2>nul
- for /f "delims=" %%a in ('findstr "src=.*http.*img.zhuoku.com.*jpg" !filename!') do (
- set "str=%%a"
- for %%b in ("!Lf!") do set "str=!str:img src=%%b!"
- for /f "delims=" %%c in ('set str^| findstr "http.*img.zhuoku.com.*jpg"') do (
- for /f %%d in (%%c) do (
- set "url=%%d"
- set "url=!url:~2,-1!"
- set "url=!url:img=bizhi!"
- set "url=!url:/thumbs=!"
- set "url=!url:tn_=!"
- wget !url!
- for %%e in ("!url!") do move %%~nxe !dirname!\
- )
- )
- )
- del "!filename!" /f
- cls&echo 下载完毕!
- pause>nul
复制代码 8、- @echo off&echo; 2>nul 3>nul
- set "cmd1=for /f "delims=" %%x in ("!str:~-1!") do set x_danwei=!%%~x!"
- set "cmd2=for /f "delims=" %%x in ("!str:~0,-1!") do set n_danwei=!%%~x!"
- setlocal enabledelayedexpansion
- set 壹=1&set 贰=2&set 叁=3&set 肆=4&set 伍=5
- set 陆=6&set 柒=7&set 捌=8&set 玖=9
- set 万=1&set 仟=1000&set 佰=100
- set 拾=10&set 圆=1&set 角=10&set 分=1
- for /f %%a in (a.txt) do (
- set str=%%a&set str=!str:整=!&set str=!str:零=!
- for %%b in (万_wan 仟_qian 佰_bai 拾_shi 圆_yuan 角_jiao 分_fen) do (
- for /f "delims=_ tokens=1,2" %%c in ("%%b") do call :decompose %%c %%d
- )
- set str=!wan!
- for %%c in (仟_q 佰_b 拾_s 万_g) do (
- for /f "delims=_ tokens=1-2" %%d in ("%%c") do (
- call :decompose %%d %%e
- ))
- for %%c in (q b s g) do (
- set str=!%%c!
- %cmd1%
- %cmd2%
- set/a sum+=!n_danwei!*!x_danwei!
- )
- set/a sum=!sum!*10000
- for %%c in (qian bai shi yuan) do (
- set str=!%%c!
- %cmd1%
- %cmd2%
- set/a sum+=!n_danwei!*!x_danwei!
- )
- for %%c in (jiao fen) do (
- set str=!%%c!
- %cmd1%
- %cmd2%
- set/a float+=!n_danwei!*!x_danwei!
- )
- set float=00!float!&set float=!float:~-2!
- set sum=0000000000!sum!!float!&set sum=!sum:~-10!
- set sort_!sum!=%%a
- for %%c in (wan qian bai shi yuan jiao fen) do set %%c=
- set sum=&set float=
- )
- echo 升序:&echo;
- for /f "delims== tokens=2" %%a in ('set sort') do echo %%a
- pause>nul
-
- :decompose
- set t=!str:*%1=!&if "!t!"=="" (set %2=!str!&goto :eof)
- set %2=!str:%t%=!& if "!%2!"=="" goto :eof
- call set str=%%str:!%2!=%%
复制代码 9、- @echo off&setlocal enabledelayedexpansion&echo; 2>nul 3>nul
- Rem 要查F盘改 ".\测试文件夹" 为 "F:"
- echo 查找中...
- md tmp123
- call :loop ".\测试文件夹"
-
- for /f "delims=" %%a in ('dir/b tmp123') do (set/a n+=1&set "arr_!n!=%%a")
- set/a u=!n!-1
- for /l %%a in (1,1,!u!) do (
- set/a low=%%a+1,up=!n!
- for /l %%b in (!low!,1,!up!) do (
- fc "tmp123\!arr_%%a!" "tmp123\!arr_%%b!" | findstr "找不到差异" >nul&&set "f_!arr_%%a!=!arr_%%b!"
- )
- )
- cls&echo 存在重复情况的目录:&echo;
- for /f "delims=_= tokens=2,3" %%a in ('set f_') do (
- set "s=%%a"&set "i=%%b"
- set "s=!s:$=:!"&set "i=!i:$=:!"
- set "s=!s:#=\!"&set "i=!i:#=\!"
- echo !s! = !i!
- )
- rd tmp123 /s/q
- pause
- goto :eof
-
- :loop
- set "fn=%~1"&set fn=!fn::=$!&set fn=!fn:\=#!
- (for /f "delims=" %%a in ('dir/a-d/b "%~1"') do echo %%a)>"tmp123\!fn!"
- for /d %%a in ("%~1\*") do call :loop "%%a"
复制代码 10、- @echo off&setlocal enabledelayedexpansion
- Rem 目录
- (
- echo ^<html^>^<body^>
- for /f "delims=" %%a in ('findstr/v "^图[0-9]*\.[0-9]*$" 时间简史.txt') do (
- set "s=%%a"
- if "!s!"=="时间简史 目录" set flag_mulu=true
- if defined flag_mulu (
- for /l %%x in (1,1,4) do set "s= !s!"
- for /f "tokens=1 delims= " %%x in ("!s!") do (
- set "t=%%x"&if "!t:~20,1!!t:~-1!"=="第章" set "s=<br>!s!"
- )
- set "s=!s!<br>"
- echo !s!
- ))
- echo ^<br^>^<br^>
- )>时间简史.htm
-
- set flag_mulu=
- Rem 正文
- (for /f "delims=" %%a in ('findstr/v "^图[0-9]*\.[0-9]*$" 时间简史.txt') do (
- set "s=%%a"
- if "!s!"=="时间简史 目录" set flag_mulu=true
- if not defined flag_mulu (
- for /l %%x in (1,1,4) do set "s= !s!"
- for /f "tokens=1 delims= " %%x in ("!s!") do (
- set "t=%%x"&if "!t:~20,1!!t:~-1!"=="第章" set "s=<font size="5" color="blue">!s!</font>"
- )
- set "s=!s!<br><br>"
- echo !s!
- ))
- echo ^</body^>^</html^>
- )>>时间简史.htm
- echo OK&pause
复制代码
|