文本数据库会被程序加载到内存中进行处理,因此运行快来还是挺快的,但加载的速度会比较慢,所以数据库的大小请保持在500kb以下。
源代码如下:- @echo off
- color 80
- path=c:\windows\system32\;%cd%
- setlocal enabledelayedexpansion
- if not "%1"=="" set file=%1 & goto start
- set /p file=请输入要新建或加载的文本数据库,注意路径中不能有引号:
- if %file%==q exit
- :start
- if not exist %file% echo.>%file%
- for /f %%a in (%file%) do (
- set /a lines+=1
- )
- if "%lines%"=="" goto mysj
- if %lines%==0 goto mysj
- findstr "PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH" %file%>%temp%\tmp
- for /f %%a in (%temp%\tmp) do (if not "%%a"=="" (goto start1) else goto start0)
-
-
-
- :start0
- set geshi=总线型
- title 总线型
- del %temp%\tmp
- set lines=0
- if not exist %file% echo.>%file%
- call :start01 %file% 正在加载数据
- echo 数据加载完成!
- ping -n 2 127.0>nul
- set status2=1
- goto readloop1
-
- :start1
- title 变量型
- set geshi=变量型
- del %temp%\tmp
-
- if not exist %file% echo.>%file%
- set lines=0
- for /f "" %%a in (%file%) do (
- set /a lines+=1
- )
-
- for /f " tokens=1* delims==" %%a in (%file%) do (
- set /a var80+=1
- set /a var90=!var80!*100/%lines%
- cls
- echo 正在加载文件...!var90!%%
- set %%a=%%b
- )
- echo 数据加载完成!
- ping -n 2 127.0>nul
- if "%a1%"=="" goto mysj
- if %a1%==0 goto mysj
- set status2=1
-
-
-
- :readloop1
- for /l %%a in (%status2%,1,%a1%) do (
- set lines=0
- cls
- call :showtopic %%a & call :readloop2 %%a
- )
- goto readloop1
-
-
-
-
-
- :msgbox
-
- echo a="第" ^& %1 ^& "条:" ^& %2>%temp%\TMP.vbs
- echo c=%4>>%temp%\TMP.vbs
- echo msgbox a,%3,c>>%temp%\TMP.vbs
- %temp%\TMP.vbs
- del %temp%\TMP.vbs
- goto :eof
-
-
-
-
- :addneiyong
- call :add 新增内容 请键入您要添加的新内容
- for /f "tokens=* delims=" %%a in (%temp%\tmp) do (set /a topic%1lines+=1 & set /a num0=%2+1 & set topic%1neiyong!num0!=%%a
- set xiugai=y)
-
- del %temp%\tmp
- goto :eof
-
-
-
-
- :baochun
- call :geshi
- if %geshi%==总线型 (
- set num3=0
- set num4=0
- del %file%
- for /l %%a in (1,1,%a1%) do (
- cls
- set /a num3+=1
- set /a num4=!num3!*100/%a1%
- echo 保存进度...!num4!%%
- echo ----------▋!topic%%a!>>%file%
- for /l %%b in (1,1,!topic%%alines!) do (
-
- echo !topic%%aneiyong%%b!>>%file%
- )
- )
- call :msgbox1 "内存中的数据已经存入文件!" 0 "当前文件:%file%"
- set xiugai=n
- )
-
- if %geshi%==变量型 (
- del %file%
- set >%file%
- call :msgbox1 "内存中的数据已经存入文件!" 0 "当前文件:%file%"
- set xiugai=n
- )
-
- goto :eof
-
-
-
-
- :msgbox1
- echo a=%1>%temp%\TMP.vbs
- echo c=%3>>%temp%\TMP.vbs
- echo msgbox a,%2,c>>%temp%\TMP.vbs
- %temp%\TMP.vbs
- del %temp%\TMP.vbs
- goto :eof
-
-
-
-
- :readloop2
- set status2=1
- for /l %%b in (1,1,!topic%1lines!) do (
- if !lines!==300 (
- call :gongneng %1
- cls
- call :showtopic %1
- set lines=0
- )
- set /a lines+=1
- call echo 第%%b条:!topic%1neiyong%%b:~0,300!
- )
- call :gongneng %1
- goto :eof
-
-
-
-
-
-
- :shanchu
- if "!topic%2lines!"=="" call :meiyouxingxi & goto :eof
- if "!topic%2lines!"=="0" call :meiyouxingxi & goto :eof
- set num3=0
- set num4=0
- set Tmp0=%1
- set Tmp1=!topic%2neiyong%1!
- for /l %%b in (1,1,!topic%2lines!) do (
- set /a num2=!topic%2lines!+1
- cls
- set /a num1=%%b+1
- set /a num3+=1
- set /a num4=!num3!*100/!topic%2lines!
- echo 删除进度...!num4!%%
- if %%b GEQ %1 call set "topic%2neiyong%%b=%%topic%2neiyong!num1!%%"
-
- )
- set /a topic%2lines-=1
- set topic%2neiyong%3=
- call :msgbox "!Tmp0!" "!Tmp1!" 0 "删除完毕"
- set xiugai=y
- set Tmp0=
- set Tmp1=
- set num1=
- set num2=
- goto :eof
-
- :shanchubiaoti
- set num0=0
- if "%a1%"=="" call :meiyoubiaoti & goto :eof
- if "%a1%"=="0" call :meiyoubiaoti & goto :eof
- set str11=!topic%1!
- for /l %%a in (1,1,!a1!) do (
- set /a num1=%%a*100/!a1!
-
- set /a var0=%%a+1
- if %%a GEQ %1 (call set "topic%%a=%%topic!var0!%%"
- call set var1=%%topic!var0!lines%%
- set "topic%%alines=!var1!" )
- for /l %%b in (1,1,!var1!) do (
- if %%a GEQ %1 call set "topic%%aneiyong%%b=%%topic!var0!neiyong%%b%%"
- )
- cls
- echo 正在删除标题%1:!str11!...!num1!%%
- )
- for /l %%a in (1,1,!topic%a1%lines!) do (set topic%a1%neiyong%%a=)
- set topic%a1%lines=
- set /a a1=!a1!-1
- call :msgbox1 "标题%1:!str11!" 0 "删除完毕"
- set xiugai=y
- goto :eof
-
- :check
- if not %xiugai%==y exit
- echo.>%temp%\tmp
- echo response=msgbox^("您有未保存的信息!是否保存?",4,"退出提示"^)>%temp%\TMP.vbs
- echo Const ForReading = 1, ForWriting = 2 >>%temp%\TMP.vbs
- echo Dim fso, f>>%temp%\TMP.vbs
- echo set fso=createobject^("scripting.filesystemobject"^).opentextfile^("%temp%\tmp",2^)>>%temp%\TMP.vbs
- echo fso.Write response >>%temp%\TMP.vbs
- call %temp%\TMP.vbs
- del %temp%\TMP.vbs
- if %xiugai%==y for /f %%a in (%temp%\tmp) do (
- if %%a == 6 call :baochun
- )
- del %temp%\tmp
- exit
- goto :eof
-
-
-
-
-
-
- :gongneng
- echo -----------------------------------------------------------------------------------------------------
- echo 功能选项(所有命令均忽略大小写,以上所显示均为简略信息):
- echo 回车:往后翻页 D:删除本标题下所有数据 条数+D:删除数据 DR:导入 N:新增内容 Q:退出程序 P:上一标题
- echo 条数+空格+ZE:进入与某条信息相同的标题 条数+空格+ZN:建立与某条信息相同的子标题
- echo S:保存数据 SO:搜寻 T:跳转 TD:删除标题 TN:新增标题 TX:修改标题 条数+空格+W:详细信息 条数+空格+X:修改信息
- set choice=
- set /p choice=请输入操作条码:
- if /i !choice! == TD call :shanchubiaoti %1
- if /i !choice! == T call :tiaozhuan
- if /i !choice! == P call :pre %1
- if /i !choice! == DR call :daoru
- if /i !choice! == SO call :soxun
- if /i !choice! == TN call :addbiaoti
- if /i !choice! == TX call :xiugaibiaoti %1
- if /i !choice! == D call :shanchuall %1
- if /i !choice! == N call :addneiyong %1 !topic%1lines!
- if /i !choice! == S call :baochun
- if /i !choice! == Q goto check
- if not "!choice!"=="" for /f "tokens=1-2 delims= " %%c in ("!choice!") do (
- if not "%%d"=="" (
- if "!topic%1neiyong%%c!"=="" call :msgbox1 "对不起,不存在此条信息,无法使用此功能!" 0 "出错提示" & set status2=%1 & goto readloop1
- if /i %%d == W call call :msgbox "%%c" "!topic%1neiyong%%c!" 0 "当前文件:%file%"
- if /i %%d == D call :shanchu %%c %1 !topic%1lines!
- if /i %%d == X call :xiugai %1 %%c
- if /i %%d == ZE call :findzi %1 %%c
- if /i %%d == ZN call :addzi %1 %%c
- )
- )
- if not "!choice!"=="" if %1 LEQ !a1! set status2=%1 & goto readloop1
- if not "!choice!"=="" if not %1 LSS !a1! set /a status2=%1-1 & goto readloop1
- goto :eof
-
-
-
-
-
-
-
- :shanchuall
- if "!topic%1lines!"=="" call :meiyouxingxi & goto :eof
- if "!topic%1lines!"=="0" call :meiyouxingxi & goto :eof
- set num3=
- for /l %%b in (1,1,!topic%1lines!) do (
- cls
- set /a num3+=1
- set /a num4=!num3!*100/!topic%1lines!
- echo 删除进度...!num4!%%
- set topic%1neiyong%%b=
- )
- set topic%1lines=0
- call :msgbox1 "标题%1的所有信息已删除完毕!" 0 "删除完毕"
- set xiugai=y
- goto :eof
-
-
-
-
- :xiugai
- if "!topic%1lines!"=="" call :meiyouxingxi & goto :eof
- if "!topic%1lines!"=="0" call :meiyouxingxi & goto :eof
- call :msgbox1 "!topic%1neiyong%2!" 0 "修改前的内容"
- set str0=!topic%1neiyong%2!
- echo i = InputBox ^("修改标题%1的第%2条信息",VbOnlyOk,"!topic%1neiyong%2!"^)>%temp%\TMP.vbs
- call :xiugai1
- for /f "tokens=* delims=" %%a in (%temp%\tmp) do (set topic%1neiyong%2=%%a
- set xiugai=y)
- del %temp%\tmp
- call :msgbox1 "标题%1的第%2条信息已被修改为!topic%1neiyong%2!" 0 "修改完毕"
- goto :eof
-
-
-
-
- :meiyouxingxi
- call :msgbox1 "对不起,本标题下无信息,不能使用此功能!" 0 "提示"
- goto :eof
-
-
-
-
-
-
- :addbiaoti
- call :add 新增标题 请键入您要添加的新标题
- for /f "tokens=* delims=" %%a in (%temp%\tmp) do (set /a a1+=1 & set topic!a1!=%%a
- set xiugai=y)
- del %temp%\tmp
- call :msgbox1 "标题新增完成!" 0 "提示"
- goto :eof
-
-
-
-
- :add
- echo i = InputBox ^("%1",VbOnlyOk, "%2"^)>%temp%\TMP.vbs
- call :xiugai1
- goto :eof
-
-
-
-
-
-
-
- :showtopic
- if "!topic%1lines!"=="" set topic%1lines=0
- if %a1%==0 call :msgbox1 "标题总数不能为0,程序将在保存数据后重启" 0 "错误提示" & call :baochun & start 简易数据库.cmd & exit
- title 已加载文件:%file% 类型:%geshi% 当前为标题%1/总有%a1%个标题 本标题共有!topic%1lines!条信息
- echo 标题%1 :!topic%1!
- echo -----------------------------------------------------------------------------------------------------
- goto :eof
-
-
-
-
- :xiugaibiaoti
- if "!a1!"=="" call :meiyoubiaoti & goto :eof
- if "!a1!"=="0" call :meiyoubiaoti & goto :eof
- call :msgbox1 "!topic%1!" 0 "修改前的标题"
- set str0=!topic%1!
- echo i = InputBox ^("修改标题%1",VbOnlyOk,"!topic%1!"^)>%temp%\TMP.vbs
- call :xiugai1
- for /f "tokens=* delims=" %%a in (%temp%\tmp) do (set topic%1=%%a
- set xiugai=y)
- del %temp%\tmp
- call :msgbox1 "标题%1已被修改为!topic%1!" 0 "修改完毕"
- goto :eof
-
- :xiugai1
- echo.>%temp%\tmp
- echo Const ForReading = 1, ForWriting = 2>>%temp%\TMP.vbs
- echo Dim fso, f>>%temp%\TMP.vbs
- echo set fso=createobject^("scripting.filesystemobject"^).opentextfile^("%temp%\tmp",2^)>>%temp%\TMP.vbs
- echo fso.Write i >>%temp%\TMP.vbs
- call %temp%\TMP.vbs
- del %temp%\TMP.vbs
- goto :eof
-
-
- :meiyoubiaoti
- call :msgbox1 "对不起,标题总数为0,不能使用此功能!" 0 "提示"
- goto :eof
-
-
-
- :tiaozhuan
- echo i = InputBox ^("您要跳转到第几个标题",VbOnlyOk,"跳转"^)>%temp%\TMP.vbs
- call :xiugai1
- for /f %%a in (%temp%\tmp) do (if %%a LEQ %a1% (set status2=%%a & del %temp%\tmp &goto readloop1) else call :msgbox1 "对不起,数值超出范围!" 0 "出错提示" )
- goto :eof
-
- :clear
- for /l %%a in (1,1,%a1%) do (
- for /l %%b in (1,1,!topic%%alines!) do (
- set topic%%aneiyong%%b=
- )
- )
- set a1=0
- set topic%%alines=
- goto :eof
-
- :geshi
- set geshi=总线型
- echo i = msgbox ^("请选择数据库格式,选'是'为总线型,选'否'为变量型",vbyesno,"提示"^)>%temp%\TMP.vbs
- call :xiugai1
- for /f %%a in (%temp%\tmp) do (if %%a==6 set geshi=总线型
- if %%a==7 set geshi=变量型)
- call :msgbox1 "您选择的数据库类型为'%geshi%'" 0 "提示"
- del %temp%\tmp
- goto :eof
-
-
- :mysj
- call :msgbox1 "数据库还没有信息,请您新增标题!" 0 "警告" & call :addbiaoti & call :baochun & call :clear & if !geshi!==总线型 (goto start0) else goto start1
- goto :eof
-
-
-
- :soxun
- if "!a1!"=="" call :meiyoubiaoti & goto :eof
- if "!a1!"=="0" call :meiyoubiaoti & goto :eof
- del %temp%\tmp
- echo i = InputBox ^("请输入您要搜索的内容。注意:搜索结果过多会遗漏信息^!",VbOnlyOk,"搜索"^)>%temp%\TMP.vbs
- call :xiugai1
- for /f %%a in (%temp%\tmp) do (set soxun=%%a)
- del %temp%\tmp
- set| findstr "%soxun%" |findstr "=" |findstr "topic">>%temp%\tmp
- set var91=
- set str14=
- set str13=
- for /f "tokens=1* delims==" %%a in (%temp%\tmp) do (
- set var91=%%a
- set var91=!var91:topic=标题!
- set var91=!var91:neiyong=信息!
- set str14=%%b
- set str14=!str14:~0,200!
- set str13=!str13! "!var91!:!str14!" ^& vbnewline ^&
- )
- echo a=!str13! vbnewline>%temp%\TMP.vbs
- echo msgbox a,0,"搜寻结果">>%temp%\TMP.vbs
- %temp%\TMP.vbs
- del %temp%\TMP.vbs
- del %temp%\tmp
- call :msgbox1 "结果显示完毕!" 0 "提示"
- goto :eof
-
-
-
-
- :daoru
- echo 请将要导入的文件拖入窗口中,不能有引号,文件名后加" 0"可导入数据库文件
- set /p file1=文件:
- for /f "tokens=1-2 delims= " %%a in ("%file1%") do (
- set lines=0
- set lines0=0
- set per0=0
- set per=0
- set a2=0
- title %%a
- if "%%b"=="" (
- set /a a1+=1
- set topic!a1!=%file1%
- for /f "" %%a in (%file1%) do (
- set /a lines+=1
- )
- if "!lines!"=="" call :mysl & goto :eof
- if !lines!==0 call :mysl & goto :eof
- for /f "tokens=* delims=" %%f in (%file1%) do (
- echo 正在读取数据...!per!%%
- set a=%%f
- set /a a2+=1 & set topic!a1!lines=!a2! & set topic!a1!neiyong!a2!=%%f
- set /a lines0+=1
- set /a per0=!lines0!*100/!lines!
- set /a per=!per0!+1
- cls
- )
-
- )
- if %%b==0 (
- findstr "PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH" %%a>%temp%\tmp
- set lines=0
- for /f %%z in (%temp%\tmp) do (set /a lines+=1)
- if !lines!==0 (call :start01 %%a 正在导入数据) else call :start11 %%a
- )
- )
- call :msgbox1 "文件已导入完毕" 0 "提示"
- set xiugai=y
- del %temp%\tmp
- goto :eof
-
-
-
-
- :start01
-
- for /f "" %%g in (%1) do (
- set /a lines+=1
- )
- if "!lines!"=="" call :mysl & goto :eof
- if !lines!==0 call :mysl & goto :eof
- if %2==正在导入数据 call :msgbox1 "要导入的数据库为总线型" 0 "提示"
- for /f " tokens=1* delims=▋" %%h in (%1) do (
- echo %2...!per!%%
- set a=%%h
- if "!a:~0,10!" == "----------" set a2=0 & set /a a1+=1 & set topic!a1!=%%i
- if not "!a:~0,10!" == "----------" set /a a2+=1 & set topic!a1!lines=!a2! & set topic!a1!neiyong!a2!=%%h
- set /a lines0+=1
- set /a per0=!lines0!*100/!lines!
- set /a per=!per0!+1
- cls
- )
- goto :eof
-
-
- :start11
-
- set var23=!a1!
- set var80=
- set var90=
- set var43=
-
- for /f "" %%i in (%1) do (
- set /a lines+=1
- )
- if "!lines!"=="" call :mysl & goto :eof
- if !lines!==0 call :mysl & goto :eof
- call :msgbox1 "要导入的数据库为变量型" 0 "提示"
- for /f " tokens=1,* delims==" %%n in (%1) do (
- if %%n==a1 set au=%%o
- )
- for /f " tokens=1,* delims==" %%i in (%1) do (
-
- set /a var80+=1
- set /a var90=!var80!*100/%lines%
- cls
- echo 正在导入数据...!var90!%%
- for /l %%l in (1,1,!au!) do (
-
- set /a var43=%%l+!a1!
- if %%i==topic%%l set topic!var43!=%%j
- if %%i==topic%%llines set topic!var43!lines=%%j & call set tmp67=%%topic!var43!lines%%
- for /l %%m in (1,1,!tmp67!) do (
- if %%i==topic%%lneiyong%%m set topic!var43!neiyong%%m=%%j
- )
- )
- )
- set /a a1=!a1!+!au!
- goto :eof
-
- :mysl
- call :msgbox1 "要导入的文件不存在或没有数据!" 0 "出错"
- goto :eof
-
-
-
- :pre
- if %1 == 1 call :msgbox1 "已到最前页!" 0 "提示" & goto :eof
- set /a status2=%1-1
- goto readloop1
-
- :findzi
- for /l %%j in (1,1,%a1%) do (if "!topic%%j!"=="!topic%1neiyong%2!" set status2=%%j & goto readloop1)
- call :msgbox1 "对不起,不存在名称为!topic%1neiyong%2!的子标题!" 0 "出错提示"
- goto :eof
-
-
- :addzi
- set /a a1+=1
- call set topic%a1%=!topic%1neiyong%2!
- call :msgbox1 "建立同名标题!topic%1neiyong%2!完成!" 0 "提示"
- goto :eof
- goto :eof
复制代码 本程序所用的数据库格式如下:
(一)总线型
----------▋请键入您要添加的新标题
1
2
3
----------▋12
123
(二)变量型
a=----------
a1=2
a2=0
ALLUSERSPROFILE=M:\Documents and Settings\All Users
APPDATA=M:\Documents and Settings\Administrator\Application Data
choice=s
CLIENTNAME=Console
CommonProgramFiles=C:\Program Files\Common Files
COMPUTERNAME=WWW-F674FB526B4
ComSpec=M:\windows\system32\cmd.exe
file=data.mdb
FP_NO_HOST_CHECK=NO
geshi=变量型
HOMEDRIVE=M:
HOMEPATH=\Documents and Settings\Administrator
lines=1
lines0=1
LOGONSERVER=\\WWW-F674FB526B4
num0=1
num3=2
num4=100
NUMBER_OF_PROCESSORS=2
OS=Windows_NT
Path=c:\windows\system32\;M:\Documents and Settings\Administrator\桌面
PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH
per=101
per0=100
PROCESSOR_ARCHITECTURE=x86
PROCESSOR_IDENTIFIER=x86 Family 6 Model 15 Stepping 13, GenuineIntel
PROCESSOR_LEVEL=6
PROCESSOR_REVISION=0f0d
ProgramFiles=C:\Program Files
PROMPT=$P$G
SESSIONNAME=Console
status2=1
SystemDrive=M:
SystemRoot=M:\windows
TEMP=Z:\Temp
TMP=Z:\Temp
topic1=请键入您要添加的新标题
topic1lines=3
topic1neiyong1=1
topic1neiyong2=2
topic1neiyong3=3
topic2=12
topic2lines=1
topic2neiyong1=123
USERDOMAIN=WWW-F674FB526B4
USERNAME=Administrator
USERPROFILE=M:\Documents and Settings\Administrator
windir=M:\windows
xiugai=n |