修改ini檔案的批處理

2021-09-07 11:17:57 字數 1083 閱讀 7028

用vbs更簡單:

vbs**:

on error resume next

dim fso,txtfl,str

set fso = createobject("

scripting.filesystemobject")

set txtfl = fso.opentextfile ("

檔案位置

",1)

str = replace ( txtfl.readall,"

被替換內容

","替換內容")

set txtfl = fso.opentextfile ("

檔案位置

",2)

txtfl.write str

txtfl.close

批處理**:

@echo off >tmp.ini

for /f "

tokens=1* delims=:

" %%i in ('

findstr /n ".*" 檔案位置

') do

( if"

%%j"=="" (echo.>>tmp.ini) else

( echo %%j|find "

被替換內容

">nul&&(

call

set tp=%%j&call echo %%tp:被替換內容=替換內容%%>>tmp.ini)||(

>>tmp.ini echo %%j)

))copy tmp.ini 檔案位置 /y >nul||(attrib -s -a -r -h 檔案位置& copy tmp.ini 檔案位置 /y >nul)

del tmp.ini

pause

批處理開啟和關閉檔案

關閉 兩種命令方法:

taskkill /f im "

要關閉的程序名

"ntsd -c q -pn "

要關閉程序名

"後者更強一點..~!開啟程式:

start

"" 「位置/程式名」

bat 批處理修改host檔案

在測試的時候,經常會遇到修改host 的情況,每次都開啟host手動新增,很繁瑣地,怎麼寫個批處理檔案,雙擊下就把host修改了呢,請看下面 echo off color 0f attrib r windir system32 drivers etc hosts echo 測試配置 beg wind...

bat 批處理修改host檔案

在測試的時候,經常會遇到修改host 的情況,每次都開啟host手動新增,很繁瑣地,怎麼寫個批處理檔案,雙擊下就把host修改了呢,請看下面 echo off color 0f attrib r windir system32 drivers etc hosts echo 測試配置 beg wind...

ini檔案處理

import configparser cfg configparser.configparser read ok cfg.read e test mysql.ini 操作之前必須先 read到記憶體中 print read ok print cfg.sections print cfg.defau...