CiaronJohn Posted December 10, 2019 Posted December 10, 2019 Hi, What do you think is the problem with my snippet below? I cannot replace the string in my text file, though I can read its position. Thanks! _FileReadToArray( $file, $FileArray) For $a = 1 To $FileArray[0] If StringInStr($FileArray[$a], 'AdScanEndSts') Then $Replaced = StringReplace( FileReadLine($filepath, $a), 'AdScanEndSts', 'AdScanEndSts1' ) _FileWriteToLine( $filepath, $a, $Replaced, 1 ) MsgBox(0, "",$Replaced) EndIf Next Here is my txt file: /********************************/ /* スタティック変数定義 */ /********************************/ static volatile UB AdScanEndSts ; /* VSG01: ADスキャン完了状態 */ /****************************************/ /* 物理対応仮想チャネルテーブル */ /****************************************/ static volatile const UB AdPhy2VcTbl[ AD_CH_MAX ] = AD_VC_TBL ; /* 物理⇒仮想変換table */
Subz Posted December 10, 2019 Posted December 10, 2019 Maybe its locked by another process or maybe its encoding, did you use FileOpen and not close the file. The following worked fine for me: #include <File.au3> $filepath = @ScriptDir & "\Filename.txt" Local $FileArray _FileReadToArray( $filepath, $FileArray) For $a = 1 To $FileArray[0] If StringInStr($FileArray[$a], 'AdScanEndSts') Then $Replaced = StringReplace( FileReadLine($filepath, $a), 'AdScanEndSts', 'AdScanEndSts1' ) _FileWriteToLine( $filepath, $a, $Replaced, 1 ) MsgBox(0, "",$Replaced) EndIf Next
CiaronJohn Posted December 10, 2019 Author Posted December 10, 2019 (edited) @Subz Thanks! I did not open the file nor close it. Edited December 10, 2019 by CiaronJohn
CiaronJohn Posted December 10, 2019 Author Posted December 10, 2019 (edited) I tried to put the sample text file in the same path where au3 file was stored, the code works. So, I think the problem is how I defined the path of my file. Local $filepath = StringTrimRight(ControlGetText( "ソフトウェア単体テスト自動化ツール D-SPIDER Ver.1.0.0", "", "WindowsForms10.EDIT.app.0.1ca0192_r11_ad11" ), 21) _FileReadToArray( $filepath & "/" & "ad_drv.c", $FileArray) $filepath was extracted from a third party application Is there anything wrong with my approach? Edited December 10, 2019 by CiaronJohn
CiaronJohn Posted December 10, 2019 Author Posted December 10, 2019 1 hour ago, Subz said: Maybe its locked by another process or maybe its encoding, did you use FileOpen and not close the file. The following worked fine for me: #include <File.au3> $filepath = @ScriptDir & "\Filename.txt" Local $FileArray _FileReadToArray( $filepath, $FileArray) For $a = 1 To $FileArray[0] If StringInStr($FileArray[$a], 'AdScanEndSts') Then $Replaced = StringReplace( FileReadLine($filepath, $a), 'AdScanEndSts', 'AdScanEndSts1' ) _FileWriteToLine( $filepath, $a, $Replaced, 1 ) MsgBox(0, "",$Replaced) EndIf Next I tried to put the sample text file in the same path where au3 file was stored, the code works. So, I think the problem is how I defined the path of my file. Local $filepath = StringTrimRight(ControlGetText( "ソフトウェア単体テスト自動化ツール D-SPIDER Ver.1.0.0", "", "WindowsForms10.EDIT.app.0.1ca0192_r11_ad11" ), 21) _FileReadToArray( $filepath & "/" & "ad_drv.c", $FileArray) $filepath was extracted from a third party application Is there anything wrong with my approach?
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now