|
maya0su
中级用户
  
积分 241
发帖 131
注册 2005-9-28
状态 离线
|
『楼 主』:
[讨论]数据查询与数据库操作脚本
使用 LLM 解释/回答一下
今天去一公司,在等待的过程中,突然有一电话问营业员某某的电话,只见那个营业员用鼠标拖着拖动条一个一个找那个名字,然后报上电话号码!
忽然觉得很可笑,就想有没有一个批处理可以解决这个问题呢?
在回来的公车上,就一直琢磨这个问题……可是等我把这个问题解决后,又觉得这个批处理的根本就没有存在的意义,因为不论是word还是excel甚至是记事本都有查找字符串的功能……哎……
不过既然写出来了,就把代码贴出来……供大家一笑……呵呵……
@echo off
set /p uu=请输入你要查找的姓名或电话号码:
type config.cfg |find /i "%uu%"
echo.
echo.
echo.
pause
exit
说明:config.cfg为CS的设置文件,估计大家知道这个,而那三个echo.是为了在寻找并显示之后,有一段空白空间,好让pause的显示不影响正常显示输出,容易观看一些!
Last edited by willsort on 2006-8-22 at 03:21 ]
Today I went to a company. During the waiting process, suddenly a phone call asked the clerk for someone's phone number. I saw that clerk drag the scroll bar with the mouse to find that name one by one and then report the phone number!
Suddenly I felt it was very funny, and I thought if there was a batch script that could solve this problem?
On the bus on the way back, I kept thinking about this problem... But after I solved this problem, I felt that the根本 existence meaning of this batch script was gone, because whether it was Word or Excel or even Notepad, there were all functions to find strings... Hey...
But since I wrote it, I'll post the code... for everyone to have a laugh... Hehe...
@echo off
set /p uu=Please enter the name or phone number you want to find:
type config.cfg |find /i "%uu%"
echo.
echo.
echo.
pause
exit
Description: config.cfg is the configuration file of CS. I estimate everyone knows this, and those three echo. are to have a blank space after finding and displaying, so that the display of pause does not affect the normal display output, making it easier to view!
Last edited by willsort on 2006-8-22 at 03:21 ]
|

房东说:这娃是个好孩子! |
|
2006-8-15 23:09 |
|
|
mornsmile
初级用户
 
积分 147
发帖 23
注册 2005-1-23
状态 离线
|
『第 2 楼』:
使用 LLM 解释/回答一下
你说的cs是指反恐吗,那跟电话什么关系
You mentioned CS, does it refer to Counter-Strike? Then what's the relation to the phone?
|
|
2006-8-16 07:28 |
|
|
xjmxjm1234
中级用户
   论坛第一菜鸟
积分 361
发帖 166
注册 2006-4-15
状态 离线
|
『第 3 楼』:
使用 LLM 解释/回答一下
cs 是寄存器吗?
好让pause的显示不影响正常显示输出,容易观看一些!
用 pause > nul 不就行了吗?
不过既然写出来了,就把代码贴出来……供大家一笑……呵呵……
没关系,批命令最重要的不是精通,创新才是。
Is `cs` a register?
So that the display of `pause` does not affect the normal display output, making it easier to watch!
Isn't it enough to use `pause > nul`?
But since it's written out, just post the code... for everyone to have a laugh... heh heh...
It doesn't matter. The most important thing about batch commands is not being proficient, but innovation.
|

Diskette Operating System |
|
2006-8-16 13:11 |
|
|
无奈何
荣誉版主
      
积分 1338
发帖 356
注册 2005-7-15
状态 离线
|
『第 4 楼』:
使用 LLM 解释/回答一下
我觉得编写脚本的目的就是方便的解决一些实际问题,只要是需要脚本编写肯定是满足特定需求的,其他的考量就是看看是否实用。
有一段时间我需要频繁的查一些地方的邮编和电话区号,我就做了下面的脚本。为了格式化输出及增强输入的容错性使用了gawk.exe。由于制作的不是太用心,所以不是太满意也就没有拿出来献丑。
使用方法是:比如要查我的老家 泰安 的邮编可以这样
1、YBQH 泰安
2、YBQH tai an
3、YBQH taian
4、YBQH ta
5、YBQH 0538
也可以空参数运行,按提示输入。其中按拼音字头会返回很多非所需结果。其他文件见附件。由于今天无法上传附件,上传系统好像也有问题,需要的话通知我一下。
YBQH.bat
- ::简易邮编区号查询程序
- ::BY 无奈何@cn-dos.net
- @echo off
- title 邮编区号查询
- echo.
- gawk -f find.awk %*
- goto next
- :loop
- echo.
- gawk -f find.awk
- :next
- echo.
- set j=
- set /p j= 按“0”键或空格键继续;其他任意键退出....
- if "%j%" == " " goto loop
- if "%j%" == "0" (goto loop) else exit
- goto :end
- :end
无奈何发表于 2006-08-16 21:51
find.awk
BEGIN {
IGNORECASE = 1
FS="\t"
if (ARGV != ""){
for (i = 1; i <= ARGC; i++) {
imput=imput " " ARGV
}
} else {
printf "请输入待查询的关键字:"
getline imput < "-"
}
gsub(/^ +| +$/,"",imput)
str=toupper(imput)
gsub(/ +/,"",str)
if (str == "") {
print "\n\t\t关键字请不要留空!"
exit
}
printf "\n\n%-10s%-16s%10s%10s\n","所属省市","地区","电话区号","邮政编码"
printf "================================================\n"
while((getline < "YBQH.txt") > 0){
if (($0~str)||(gensub(/ +/,"","g",$3)~str)) {
printf "%-10s%-16s%10s%10s\n",$1,$2,$5,$6
flag=1
}
}
print "\n"
if (flag==0)
print "\t\t无此关键字记录!\n"
}
I think the purpose of writing a script is to conveniently solve some practical problems. As long as script writing is needed, it must meet specific requirements. The other consideration is just to see if it is practical.
There was a period when I needed to frequently check the postal codes and area codes of some places, so I made the following script. In order to format the output and enhance the fault tolerance of input, gawk.exe was used. Since it was not made very carefully, I was not very satisfied and did not show it off.
The usage method is: for example, to check the postal code of my hometown Tai'an, it can be like this
1、YBQH 泰安
2、YBQH tai an
3、YBQH taian
4、YBQH ta
5、YBQH 0538
It can also run with empty parameters and input according to the prompt. Among them, returning many non-desired results according to the initials of pinyin. Other files are in the attachment. Since I can't upload the attachment today, there seems to be a problem with the upload system. Let me know if you need it.
YBQH.bat
- ::Simple postal code and area code query program
- ::BY 无奈何@cn-dos.net
- @echo off
- title Postal code and area code query
- echo.
- gawk -f find.awk %*
- goto next
- :loop
- echo.
- gawk -f find.awk
- :next
- echo.
- set j=
- set /p j= Press "0" key or space bar to continue; any other key to exit....
- if "%j%" == " " goto loop
- if "%j%" == "0" (goto loop) else exit
- goto :end
- :end
Written by 无奈何 on 2006-08-16 21:51
find.awk
BEGIN {
IGNORECASE = 1
FS="\t"
if (ARGV != ""){
for (i = 1; i <= ARGC; i++) {
imput=imput " " ARGV
}
} else {
printf "Please enter the keyword to be queried: "
getline imput < "-"
}
gsub(/^ +| +$/,"",imput)
str=toupper(imput)
gsub(/ +/,"",str)
if (str == "") {
print "\n\t\tThe keyword should not be left blank!"
exit
}
printf "\n\n%-10s%-16s%10s%10s\n","Province and city","Area","Area code","Postal code"
printf "================================================\n"
while((getline < "YBQH.txt") > 0){
if (($0~str)||(gensub(/ +/,"","g",$3)~str)) {
printf "%-10s%-16s%10s%10s\n",$1,$2,$5,$6
flag=1
}
}
print "\n"
if (flag==0)
print "\t\tNo record with this keyword!\n"
}
|

☆开始\运行 (WIN+R)☆
%ComSpec% /cset,=何奈无── 。何奈可无是原,事奈无做人奈无&for,/l,%i,in,(22,-1,0)do,@call,set/p= %,:~%i,1%<nul&ping/n 1 127.1>nul
|
|
2006-8-16 22:19 |
|
|
hanbsome
初级用户
 
积分 36
发帖 14
注册 2006-4-29
状态 离线
|
『第 5 楼』:
使用 LLM 解释/回答一下
强 这样的批处理都搞出来了 佩服
Wow, you've even come up with such a batch script. I'm impressed.
|
|
2006-8-16 22:43 |
|
|
maya0su
中级用户
  
积分 241
发帖 131
注册 2005-9-28
状态 离线
|
『第 6 楼』:
使用 LLM 解释/回答一下
CS是反恐的配置文件,不过这里我是用那个代替电话本的!
我有个不好习惯,就是总是把实际的文件都贴出来,而不是真正我设想的文件
看了无奈何版主的代码,我觉得我的代码还是需要再完善一点的
其实代码的有用与无用无关紧要,最主要的是,我们需要去思考,是不是能让电脑让生活更简单……
CS is the configuration file for Counter-Strike, but here I'm using it as a substitute for a phone book!
I have a bad habit, which is always posting the actual files instead of the files I actually envisioned.
After reading the code of the helpless version master, I think my code still needs to be improved a bit.
In fact, it doesn't matter whether the code is useful or not. The most important thing is that we need to think about whether we can make the computer make life simpler...
|

房东说:这娃是个好孩子! |
|
2006-8-16 22:52 |
|
|
3742668
荣誉版主
      
积分 2013
发帖 718
注册 2006-2-18
状态 离线
|
『第 7 楼』:
使用 LLM 解释/回答一下
可是等我把这个问题解决后,又觉得这个批处理的根本就没有存在的意义,因为不论是word还是excel甚至是记事本都有查找字符串的功能……哎……
你也不用太妄自菲薄了,且不说不管有用没用,每写一次脚本对写脚本的能力都会有所提高,单是脚本的灵活多样性,就不是大众化的程序所能比拟的。当然,没有大众化的应用程序,那么脚本的功能也会受到很大的影响。其实我的主要观点是: 不要把脚本和应用程序放在对立的面上,而是应该考虑怎么能让脚本结合应用程序更大地发挥它们的作用。
例如,以下是把我以前的几个脚本拼凑起来的东东:
BAT文件部分:
@echo off
:start
setlocal
cls
echo 1.添加记录
echo 2.查询记录
echo 3.保存记录为csv格式
echo 4.保存为数据库
echo 5.从网页查看数据
echo 其他任意键退出...
set /p var=选择:
set var=%var:~0,1%
call :%var% %0 2>nul || goto :eof
endlocal
goto start
:1
setlocal
cls
echo 输入记录:
set /p str=
echo %str% >>%1
if exist 电话号码数据库.mdb wscript.exe 数据库脚本.vbs /a %str%
endlocal
goto :eof
:2
setlocal
cls
echo 输入查询条件:
set /p str=
cls
more +52 %1 | findstr %str% || echo 记录不存在!
echo.&echo 按任意键回到主菜单! & pause>nul
endlocal & dir >nul
goto :eof
:3
setlocal >记录.csv
for /f "skip=52 tokens=1,2" %%i in (%~fsnx1) do echo %%i,%%j >>记录.csv
endlocal
goto :eof
:4
wscript.exe 数据库脚本.vbs /c %1 && echo 操作完毕!
pause
goto :eof
:5
wscript.exe 数据库脚本.vbs
goto :eof
注意:代码末尾有个回车,文件名可以随意。
VBS文件部分:
Set objArgs = WScript.Arguments
strDataName = "电话号码数据库.mdb"
strTableName = "MyTelTable"
On Error Resume Next
If WScript.Arguments.Count <> 0 Then
Select Case objArgs(0)
Case "/c" bat2mdb
Case "/a" If Not AddRecord(objArgs(1),objArgs(2)) Then bat2mdb
Case Else PrintData
End Select
Else
PrintData
End If
'****************************************************************************
'bat2mdb
'****************************************************************************
Sub bat2mdb()
CreateDataBase
With CreateObject("Scripting.FileSystemObject").OpenTextFile(objArgs(1))
For i = 1 to 52
.skipline
Next
Do While .AtEndOfStream <> True
On Error Resume Next
strArray = Split(.ReadLine)
AddRecord strArray(0),strArray(1)
Loop
End With
End sub
'****************************************************************************
'创建数据库文件
'****************************************************************************
Sub CreateDataBase()
On Error Resume Next
CreateObject("Adox.Catalog").Create ( _
"Provider = Microsoft.Jet.OLEDB.4.0; " & _
"Data Source =" & strDataName )
'建立一个新表
Set objConnection = CreateObject("ADODB.Connection")
objConnection.Open _
"Provider= Microsoft.Jet.OLEDB.4.0; " & _
"Data Source=" & strDataName
objConnection.Execute( "CREATE TABLE " & strTableName & _
"(Name TEXT(10) , Tel TEXT(20) )" )
End Sub
'****************************************************************************
'添加数据
'****************************************************************************
Function AddRecord(strName,strTel)
On Error Resume Next
Set objConnection = CreateObject("ADODB.Connection")
Set objRecordSet = CreateObject("ADODB.Recordset")
AddRecord = objConnection.Open( _
"Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & strDataName )
objRecordSet.Open _
"SELECT * FROM " & strTablename, objConnection, 3, 3
objRecordSet.AddNew
objRecordSet("Name") = strName & space(1)
objRecordSet("Tel")= strTel & space(1)
objRecordSet.Update
End Function
'****************************************************************************
'获得HTML代码
'****************************************************************************
Function GetStrHtml()
strHTML = "<table border='1' style='border-collapse: collapse' " & _
"bordercolor='#111111' width='100%' id='Table1' >"
strHTML = strHTML & "<tr><td>姓名</td><td>电话</td></tr>"
Set objConnection = CreateObject("ADODB.Connection")
Set objRecordSet = CreateObject("ADODB.Recordset")
objConnection.Open _
"Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & strDataName
objRecordSet.Open _
"SELECT * FROM " & strTablename, objConnection, 3, 3
objRecordSet.MoveFirst
Do Until objRecordSet.EOF
strHTML = strHTML & "<tr>"
for i = 1 to objrecordset.fields.count
strHTML = strHTML & "<td>" & objrecordset.fields(i - 1) & "</td>"
next
strHTML = strHTML & "</tr>"
objRecordSet.MoveNext
Loop
GetStrHtml = strHTML & "</table>"
End Function
'****************************************************************************
'显示数据
'****************************************************************************
Sub PrintData()
Set objIE = Wscript.CreateObject("InternetExplorer.Application")
With objIE
.menubar = 0
.addressbar = 0
.toolbar = 0
.statusbar = 0
.resizable = 0
.width = 400
.height = 500
.navigate "about:blank"
.left = fix((.document.parentwindow.screen.availwidth-.width)/2)
.top = fix((.document.parentwindow.screen.availheight-.height)/2)
.visible = 1
end With
With objIE.Document
.Write "<HTML><HEAD><TITLE>电话数据库</TITLE></HEAD>"
.Write "<BODY STYLE='font:14pt arial; color:white;"
.Write "filter:progid:DXImageTransform.Microsoft.Gradient"
.Write "(GradientType=0, StartColorStr=#800000, EndColorStr=#DB7093)'>"
.Write "<DIV id='WriteStr'></DIV>"
.Write "<HR COLOR=#DB7093></FONT></CENTER></BODY></HTML>"
end With
Set objDiv = objIE.Document.All.WriteStr
objDiv.innerHTML = GetStrHtml()
End Sub
注意:保存的文件名必须为: 数据库脚本.vbs
本来打算把vbs文件放在bat里面echo出来的,由于代码太长了,所以就分开为了两个文件。由于代码由我以前的几个脚本拼凑而来,所以难免有所不足,大家可以自行修改了耍耍。
But after I solved this problem, I felt that this batch processing doesn't have any meaning at all, because both Word and Excel, and even Notepad, have the function of finding strings... Hey...
You don't need to be too self-deprecating. Not to mention whether it's useful or not, every time you write a script, your ability to write scripts will improve. Simply the flexibility and diversity of scripts are incomparable to popularized programs. Of course, without popularized applications, the functions of scripts will also be greatly affected. In fact, my main point is: Don't put scripts and applications on opposite sides, but should consider how to make scripts combine with applications to play their roles more greatly.
For example, the following is something pieced together from a few of my previous scripts:
BAT file part:
@echo off
:start
setlocal
cls
echo 1. Add record
echo 2. Query record
echo 3. Save record as csv format
echo 4. Save as database
echo 5. View data from web page
echo Any other key to exit...
set /p var=Choose:
set var=%var:~0,1%
call :%var% %0 2>nul || goto :eof
endlocal
goto start
:1
setlocal
cls
echo Enter record:
set /p str=
echo %str% >>%1
if exist 电话号码数据库.mdb wscript.exe 数据库脚本.vbs /a %str%
endlocal
goto :eof
:2
setlocal
cls
echo Enter query condition:
set /p str=
cls
more +52 %1 | findstr %str% || echo Record not found!
echo.&echo Press any key to return to main menu! & pause>nul
endlocal & dir >nul
goto :eof
:3
setlocal >记录.csv
for /f "skip=52 tokens=1,2" %%i in (%~fsnx1) do echo %%i,%%j >>记录.csv
endlocal
goto :eof
:4
wscript.exe 数据库脚本.vbs /c %1 && echo Operation completed!
pause
goto :eof
:5
wscript.exe 数据库脚本.vbs
goto :eof
Note: There is a carriage return at the end of the code, and the file name can be arbitrary.
VBS file part:
Set objArgs = WScript.Arguments
strDataName = "电话号码数据库.mdb"
strTableName = "MyTelTable"
On Error Resume Next
If WScript.Arguments.Count <> 0 Then
Select Case objArgs(0)
Case "/c" bat2mdb
Case "/a" If Not AddRecord(objArgs(1),objArgs(2)) Then bat2mdb
Case Else PrintData
End Select
Else
PrintData
End If
'****************************************************************************
'bat2mdb
'****************************************************************************
Sub bat2mdb()
CreateDataBase
With CreateObject("Scripting.FileSystemObject").OpenTextFile(objArgs(1))
For i = 1 to 52
.skipline
Next
Do While .AtEndOfStream <> True
On Error Resume Next
strArray = Split(.ReadLine)
AddRecord strArray(0),strArray(1)
Loop
End With
End sub
'****************************************************************************
'Create database file
'****************************************************************************
Sub CreateDataBase()
On Error Resume Next
CreateObject("Adox.Catalog").Create ( _
"Provider = Microsoft.Jet.OLEDB.4.0; " & _
"Data Source =" & strDataName )
'Create a new table
Set objConnection = CreateObject("ADODB.Connection")
objConnection.Open _
"Provider= Microsoft.Jet.OLEDB.4.0; " & _
"Data Source=" & strDataName
objConnection.Execute( "CREATE TABLE " & strTableName & _
"(Name TEXT(10) , Tel TEXT(20) )" )
End Sub
'****************************************************************************
'Add data
'****************************************************************************
Function AddRecord(strName,strTel)
On Error Resume Next
Set objConnection = CreateObject("ADODB.Connection")
Set objRecordSet = CreateObject("ADODB.Recordset")
AddRecord = objConnection.Open( _
"Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & strDataName )
objRecordSet.Open _
"SELECT * FROM " & strTablename, objConnection, 3, 3
objRecordSet.AddNew
objRecordSet("Name") = strName & space(1)
objRecordSet("Tel")= strTel & space(1)
objRecordSet.Update
End Function
'****************************************************************************
'Get HTML code
'****************************************************************************
Function GetStrHtml()
strHTML = "<table border='1' style='border-collapse: collapse' " & _
"bordercolor='#111111' width='100%' id='Table1' >"
strHTML = strHTML & "<tr><td>Name</td><td>Tel</td></tr>"
Set objConnection = CreateObject("ADODB.Connection")
Set objRecordSet = CreateObject("ADODB.Recordset")
objConnection.Open _
"Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & strDataName
objRecordSet.Open _
"SELECT * FROM " & strTablename, objConnection, 3, 3
objRecordSet.MoveFirst
Do Until objRecordSet.EOF
strHTML = strHTML & "<tr>"
for i = 1 to objrecordset.fields.count
strHTML = strHTML & "<td>" & objrecordset.fields(i - 1) & "</td>"
next
strHTML = strHTML & "</tr>"
objRecordSet.MoveNext
Loop
GetStrHtml = strHTML & "</table>"
End Function
'****************************************************************************
'Display data
'****************************************************************************
Sub PrintData()
Set objIE = Wscript.CreateObject("InternetExplorer.Application")
With objIE
.menubar = 0
.addressbar = 0
.toolbar = 0
.statusbar = 0
.resizable = 0
.width = 400
.height = 500
.navigate "about:blank"
.left = fix((.document.parentwindow.screen.availwidth-.width)/2)
.top = fix((.document.parentwindow.screen.availheight-.height)/2)
.visible = 1
end With
With objIE.Document
.Write "<HTML><HEAD><TITLE>Phone Database</TITLE></HEAD>"
.Write "<BODY STYLE='font:14pt arial; color:white;"
.Write "filter:progid:DXImageTransform.Microsoft.Gradient"
.Write "(GradientType=0, StartColorStr=#800000, EndColorStr=#DB7093)'>"
.Write "<DIV id='WriteStr'></DIV>"
.Write "<HR COLOR=#DB7093></FONT></CENTER></BODY></HTML>"
end With
Set objDiv = objIE.Document.All.WriteStr
objDiv.innerHTML = GetStrHtml()
End Sub
Note: The saved file name must be: 数据库脚本.vbs
Originally planned to echo the vbs file in the bat, but because the code is too long, it is separated into two files. Since the code is pieced together from a few of my previous scripts, there are inevitable deficiencies, and everyone can modify it by themselves for fun.
附件
1: 脚本.rar (2006-8-17 20:44, 2.05 KiB, 下载附件所需积分 1 点
,下载次数: 37)
|
|
2006-8-17 20:44 |
|
|
zrz000
初级用户
 
积分 44
发帖 16
注册 2006-8-15
状态 离线
|
『第 8 楼』:
使用 LLM 解释/回答一下
又学到了不少..以后要多上来看看///
I've learned a lot again.. I need to come up more often in the future///
|
|
2006-8-18 18:39 |
|
|
maya0su
中级用户
  
积分 241
发帖 131
注册 2005-9-28
状态 离线
|
『第 9 楼』:
使用 LLM 解释/回答一下
RE:3742668
请问如下
more +52 %1 | findstr %str% || echo 记录不存在!
1. more +52 %1 是什么意思?
2. || echo 记录不存在! 为什么要用二个管道符?
麻烦请解释一下!
谢谢
### 1. What does `more +52 %1` mean?
`more` is a command in DOS (Disk Operating System) used to view the content of a file. The `+52` option means to start displaying the file starting from the 52nd line. `%1` is a batch file parameter, which represents the first command-line argument passed to the batch script. So `more +52 %1` means to use the `more` command to display the file passed as the first argument starting from the 52nd line.
### 2. Why use two pipe symbols for `|| echo 记录不存在!`?
In batch scripting, the `||` operator is a logical OR operator. It means that if the preceding command (in this case, `findstr %str%`) returns a non-zero exit code (indicating that the search did not find a match), then the command following `||` (here, `echo 记录不存在!`) will be executed. So `findstr %str% || echo 记录不存在!` means: if `findstr %str%` does not find the string `%str%`, then output "记录不存在!" (which means "Record does not exist!"). The two pipe symbols are used to connect the `findstr %str%` command and the `echo 记录不存在!` command in the logical OR structure.
|

房东说:这娃是个好孩子! |
|
2006-8-20 11:17 |
|
|
namejm
荣誉版主
       batch fan
积分 5226
发帖 1737
注册 2006-3-10 来自 成都
状态 离线
|
『第 10 楼』:
使用 LLM 解释/回答一下
Originally posted by maya0su at 2006-8-20 11:17:
请问如下
more +52 %1 | findstr %str% || echo 记录不存在!
1. more +52 %1 是什么意思?
2. || echo 记录不存在! 为什么要用二个管道符?
麻烦请解释一丠...
1、从第52行之后开始显示文件内容;
2、||并非两个管道符号的连用,而是表示如果前面的语句执行失败,则执行之后的语句;类似的还有&&,表示前面的语句执行成功之后才执行后面的语句;
Last edited by namejm on 2007-2-5 at 10:41 AM ]
Originally posted by maya0su at 2006-8-20 11:17:
Please ask the following
more +52 %1 | findstr %str% || echo Record not found!
1. What does more +52 %1 mean?
2. Why use two pipe symbols for || echo Record not found!?
Please explain...
1. Display the content of the file starting from line 52;
2. || is not the use of two consecutive pipe symbols, but it means that if the previous statement fails to execute, then the subsequent statement is executed; similarly, && means that the subsequent statement is executed only after the previous statement is executed successfully;
Last edited by namejm on 2007-2-5 at 10:41 AM ]
|

尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。 |
|
2006-8-20 13:32 |
|
|
maya0su
中级用户
  
积分 241
发帖 131
注册 2005-9-28
状态 离线
|
『第 11 楼』:
使用 LLM 解释/回答一下
@echo off
title 电话本查找工具
color 0A
:start
cls
echo.
echo.
echo 查找电话或姓名----1
echo 添加电话或姓名----2
echo 退出本程序--------3
echo.
echo.
set /p var=选择:
set var=%var:~0,1%
call :%var% %0 2>nul || goto :eof
:1
cls
set /p uu=请输入你要查找的姓名或电话号码:
type 电话本.txt | find /i "%uu%" || echo 没有找到你要查找的姓名和电话
echo.
echo.
echo.
pause
goto :start
:2
cls
set /p nn=请输入你要添加的姓名和电话:
echo %nn% >>电话本.txt
echo 添加完毕.
echo.
echo.
echo.
pause
goto :start
:end
exit
在继续完善之后,我想知道,如何给这个批处理上加上,“删除”这个选项?
To add a "delete" option to this batch script, you can modify it as follows:
```batch
@echo off
title 电话本查找工具
color 0A
:start
cls
echo.
echo.
echo 查找电话或姓名----1
echo 添加电话或姓名----2
echo 删除电话或姓名----3
echo 退出本程序--------4
echo.
echo.
set /p var=选择:
set var=%var:~0,1%
call :%var% %0 2>nul || goto :eof
:1
cls
set /p uu=请输入你要查找的姓名或电话号码:
type 电话本.txt | find /i "%uu%" || echo 没有找到你要查找的姓名和电话
echo.
echo.
echo.
pause
goto :start
:2
cls
set /p nn=请输入你要添加的姓名和电话:
echo %nn% >>电话本.txt
echo 添加完毕.
echo.
echo.
echo.
pause
goto :start
:3
cls
set /p del_str=请输入要删除的姓名或电话号码:
findstr /v /c:"%del_str%" 电话本.txt > temp.txt
move /y temp.txt 电话本.txt >nul
echo 删除完毕.
pause
goto :start
:4
exit
```
Here's the explanation of the added part:
- Added a new option "3" for deleting.
- In the `:3` label, it uses `findstr /v` to find lines that do not match the string to be deleted, saves the result to a temporary file, and then moves the temporary file back to replace the original phone book file to achieve the deletion function.
|

房东说:这娃是个好孩子! |
|
2006-9-4 08:36 |
|
|