Probably a bug and also one question about regex replacement in file Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
john_c
Posts: 493
Joined: 05 May 2017, 13:19

Probably a bug and also one question about regex replacement in file

18 Feb 2018, 16:21

I have 2 questions regarding to this script.

First of all, it seems I found a bug, but I'm not sure. Try to launch it. Each time when you press F1 you will see the same time. Why?

Also, if you remove the last line (i.e. fileAppend), the time will be counted normally. ("Bug" will be "fixed").

So, is it really a bug or not? How to fix it?

I use AHK 1.1.27.07 on Win7.

***

Secondly, it's interesting for me is there a way to perform regEx replacement in file without using fileDelete+fileAppend?

***

Now, the code. There are two files:

Original.txt:

Code: Select all

foo 123
Test.ahk:

Code: Select all

f1::
	fileCopy, Original.txt, Temp.txt

	; Sleeps are for better reliability. Try to remove them - no difference
	sleep, 500
	fileRead, varContainingFileContent, Temp.txt

	formatTime, timestamp,, HH:mm:ss
	replaced := regExReplace(varContainingFileContent, "foo \d+", timestamp)
	msgBox, %replaced%

	ifExist, Temp.txt
		fileDelete, Temp.txt
	sleep, 500

	; Try to remove this line:
	fileAppend, %replaced%, Temp.txt
return
User avatar
boiler
Posts: 16925
Joined: 21 Dec 2014, 02:44

Re: Probably a bug and also one question about regex replacement in file  Topic is solved

18 Feb 2018, 23:33

As is usually the case when people think they found a bug, it's not a bug. It did exactly what you told it to do. With the last line in there, you write the time in the temp file (and that's all that's there because you deleted it before). Then the next time you press F1, that file is still there. It has the old time in it. It doesn't have "foo 123" in it because your FileCopy command failed. You did not allow it to overwrite existing files.
john_c
Posts: 493
Joined: 05 May 2017, 13:19

Re: Probably a bug and also one question about regex replacement in file

19 Feb 2018, 06:26

boiler wrote:...
Thanks. Now I understand.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: AHK_user and 205 guests