批处理修改ini文件的某个[]下的busno参数,支持键盘
时间: 2024-03-08 13:47:31 浏览: 26
您可以使用以下批处理代码来修改INI文件中某个`[]`下的`busno`参数,并支持键盘输入:
```
@echo off
set /p section="请输入要修改的部分名:"
set value=
set /p value="请输入新的参数值:"
set file="C:\path\to\file.ini"
setlocal enabledelayedexpansion
set found=0
for /f "usebackq delims=" %%a in (%file%) do (
set line=%%a
if "!line:~0,1!"=="[" (
set current_section=!line:~1,-1!
if /i "!current_section!"=="!section!" (
set found=1
) else (
set found=0
)
)
if !found!==1 (
for /f "tokens=1,* delims==" %%b in ("!line!") do (
if /i "%%b"=="busno" (
set line=%%b=!value!
)
)
)
echo !line! >> %file%.new
)
move /y %file%.new %file%
```
将上述代码中的`section`变量替换为您要修改的部分名称,将`value`变量留空,它将在运行时提示您输入新的参数值,将`file`变量替换为您要修改的INI文件的完整路径和文件名。运行批处理后,它将提示您输入新的`busno`参数值,并将在INI文件中查找匹配的部分和参数,并将其替换为新值。最后,它将将修改后的INI文件保存回原始文件中。
相关推荐
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)