所谓作品,不过是给自己以后工作生活以便利,记录下来备忘而已,Windows 平台还是要会 Powershell 才是王道
1. 根据输入数字算年龄
@echo off
color 9f
title Game by Frank
::mod col=80
setlocal enabledelayedexpansion
echo This game is to get your age according to the entered number.
set /p FirstNumber=Please enter the first number that you have thought already :
set /a Result=(2*%FirstNumber%+5)*50
::echo !Result!
set /p BirFlag=Whether your birthday has been already passed or not? (Y/N) :
IF /i %BirFlag%=="Y" (set /a Result=!Result!+1766) ELSE (set /a Result=!Result!+1765)
set /p DOB=Please enter your birthday (yyyy) :
set /a Result=!Result!-%DOB%
set /a FirstNumber=!Result!/100
set /a Age =!Result!%%100
::echo !Result!
echo The number you chose : !FirstNumber!
echo And your age : !Age!
::echo on
::FOR /l %%i in (1,1,3) do (@echo )
echo %0 Thank you for running this game, and enjoy yourself^^!
pause>nul
2.递归某个 srcFolder 递归拷贝其下面所有子文件夹中的文件
@echo off
title copy files (*.*) from source folder( actutally it's sub-folder recursively) to target folder by Frank v1.2
color 1f
mode con cols=115 lines=25
setlocal EnableDelayedExpansion
set /p srcFolder= Please enter the src folder:
set /p tarFolder= Please enter the tar folder:
for /f "delims=" %%i in ('dir /ad /b /s !srcFolder!') do copy "%%i"*.* !tarFolder!
::copy !srcFolder!\%%i*.* !tarFolder!
pause
3. 拷贝并重命名文件
@echo off
title FrnkCopyFilesAndRename 1,2,3......
color 9f
mode con cols=60 lines=20
setlocal enabledelayedexpansion
set var=0
set SrcFolder="C:UsersGhcDesktopMydir"
set regRule="*.txt"
for %%i in (%SrcFolder%%regRule%) do (
set /a var=!var!+1
copy %%i %SrcFolder%new2!var!.txt
)
echo All the files have been copied successfully!
pause>nul
4、双击开仨QQ
@echo off
Title StartQQ3Timesbat
color 27
mode 60,80
for %%i in (1,1,3) do "F:Program Files (x86)BinQQScLauncher.exe"
5、网络磁盘映射
@echo off
rem my bat script start
Title NetDiskBat
Color 27
Mode 40,20
net use w: \192.168.0.5
ewshare
echo Congratulations! New Share Folder has been set as local driver w!!!
pause>nul
删除网络磁盘映射
net use w: /del
6、输出特殊字符
@echo off
rem set color
color 24
title Frank batch script
echo ^^ ^> ^>^> ^& ^&^& ^| ^|^|
echo Press any key to exit&pause>nul
7. 选择分支
@echo off
setlocal enabledelayedexpansion
set /p a=Do you love me? (Y/N)
if /i !a!== y echo mee too
pause>nul
8. 循环分支
@echo off
setlocal enabledelayedexpansion
set var=0
for /l %%i in (1,1,10) do (
set /a var=%%i+!var!
set /a tem2=!var!
set /a tem1=%var%
echo tem1:%tem1% tem2:!tem2! var:!var!
)
pause>nul
9.批处理设置 Wlan
@echo off
netsh wlan set hostednetwork mode=allow
netsh wlan set hostednetwork ssid=WiFi key=12345678
:+ ssid=无线名称 key=密码8位以上 这里都自己设置吧
netsh wlan start hostednetwork
net start ALG
net start BFE
net start MpsSvc
echo 已开启!
pause
10.批量解压某个目录下 zip 文件到指定目录
cls & @echo off
title 7z to extract file out
color 0a
mode con cols=115 lines=25
set /p filePath=please enter the the folder name that zip belongs to
if not defined filePath goto defa
:param
pushd %filePath% && for /f %%i in ('dir /b /a-d *.* ^| find /i ".zip"') do "C:Program Files7-Zip"7z.exe x -aos -y -o%%~dpi %%i
popd
goto end
:defa
pushd \defaultpathfolder && for /f %%i in ('dir /b /a-d *.* ^| find /i ".zip"') do "C:Program Files7-Zip"7z.exe x -aos -y -o%%~dpi %%i
popd
goto end
:end
echo.
ping -n 2 127.0.0.1
echo files have been extracted successully^!^!
pause>nul
效果图 :