Page 1 of 1
Ahk loop read file extremely slow in windows 10
Posted: 10 Dec 2016, 12:03
by sv270190
autohotkey scripts loop read file is extremely slow in windows 10
the same script is fast in win 7. being dead slow it defeats the very purpose of using autohotkey
please guide me as to speed up ahk in win 10 also as it worked in win xp and win 7
#SingleInstance, force
ListLines,Off
SetBatchLines, -1
SetTitleMatchMode,3
#MaxThreads,20
mstart = %a_now%
Loop,Read,d:\custdet\sample.txt
FileAppend,%A_LoopReadLine%,d:\custdet\custdet02.rpt
mend = %a_now%
MsgBox, % mend-mstart
Re: Ahk loop read file extremely slow in windows 10
Posted: 10 Dec 2016, 12:49
by just me
I have noticed no such problem here as yet.
Code: Select all
Loop,Read,d:\custdet\sample.txt
FileAppend,%A_LoopReadLine%,d:\custdet\custdet02.rpt
Do you try to copy the file without EOLs?
Re: Ahk loop read file extremely slow in windows 10
Posted: 10 Dec 2016, 18:51
by lexikos
Do you have different antivirus or SATA/AHCI/IDE controller drivers?
Maybe it's not much slower - you are measuring it incorrectly. It is not valid to use subtraction within an expression on the timestamp returned by A_Now. For example, ..90000 - ..85959 = 4041, but it's really only really only one second. You should use A_TickCount instead.
Assuming your code does what you want, I would suggest utilising the
OutputFile parameter so that you don't have to open and close the output file on every iteration. Keeping the file open allows AutoHotkey to buffer the disk access more efficiently.
Code: Select all
Loop, Read, d:\custdet\sample.txt, d:\custdet\custdet02.rpt
FileAppend, %A_LoopReadLine%
Re: Ahk loop read file extremely slow in windows 10
Posted: 11 Dec 2016, 05:11
by sv270190
" Do you have different antivirus or SATA/AHCI/IDE controller drivers?"
1. WINDOWS DEFENTER is the only antivirus I use in the system.
2. SATA/AHCI/IDE controller drivers ------------- I do not follow. how to know about it.
3. my system is win 10 64x
" I would suggest utilising the OutputFile parameter so that you don't have to open and clos"
sir where to put this 'outputfile' / how to use the outputfile parameter
loop read myfile,outputfile or
fileappend,%a_loopreadline%`n,outputfile
kindly correct the code
the actual data file took 400 seconds where is the same data file takes only 17 seconds in WIN 7
Re: Ahk loop read file extremely slow in windows 10
Posted: 11 Dec 2016, 05:29
by just me
So the only change on your system was the update from Win 7 to Win 10?
sv270190 wrote:sir where to put this 'outputfile' / how to use the outputfile parameter
lexikos wrote:Code: Select all
Loop, Read, d:\custdet\sample.txt, d:\custdet\custdet02.rpt
FileAppend, %A_LoopReadLine%`n ; just me: added line feed
If you just want to append the contents of one file to another, you might want to use
FileRead to get the contents and one
FileAppend to append it.
Re: Ahk loop read file extremely slow in windows 10
Posted: 11 Dec 2016, 05:51
by sv270190
SIR, resolved the issue - with your help --- a million thanks
I USED "Loop,READ,D:\CUSTDET\custdet.TXT,D:\CUSTDET\CUSTDET.RPT"
IT took less than a second, so I used a_tickcount 296 milli seconds -- time for execution
thanks again for this has solved not only this problem but also it boosted my self confidence / interest in learning this wonderful tool -- your people / forum is here to come to our help
my doubt :- when this works fantastically why and what is the logic in keeping this parameter as optional.
under what circumstances fileappend, var, filename is better and desirable. ( in this case it is criminal waste of time)
Re: Ahk loop read file extremely slow in windows 10
Posted: 11 Dec 2016, 06:05
by just me
sv270190 wrote:my doubt :- when this works fantastically why and what is the logic in keeping this parameter as optional.
Because
FileAppend is not always used within a file-reading loop.
Re: Ahk loop read file extremely slow in windows 10
Posted: 11 Dec 2016, 06:46
by sv270190
thanks for your clarification
Re: Ahk loop read file extremely slow in windows 10
Posted: 11 Dec 2016, 09:01
by garry
woul'd use loop if you want check something in lines
here another examples
Code: Select all
/*
;- example-1
f1=%a_scriptdir%\sample.txt
f2=%a_scriptdir%\custdet02.rpt
ifnotexist,%f2%
{
Fileread,aaa,%f1%
Fileappend,%aaa%,%f2%
}
aaa=
return
*/
;- example-2
f1=%a_scriptdir%\sample.txt
f2=%a_scriptdir%\custdet02.rpt
FileCopy, %f1%,%f2%
if (errorlevel<>0 or a_lasterror <>0 )
{
erl:=errorlevel
list .= "ERROR`nSource=" . f1 . "`nDestination=" . f2 . "`nLasterror=" a_lasterror . "`nErrorlevel=" . erl . "`n"
msgbox %list%
}
if (errorlevel=0 and a_lasterror=0)
{
erl:=errorlevel
aa := "NO ERROR`nSource=" . f1 . "`nDestination=" . f2 . "`nLasterror=" a_lasterror . "`nErrorlevel=" . erl . "`n"
msgbox,%aa%
}
return
Re: Ahk loop read file extremely slow in windows 10
Posted: 11 Dec 2016, 11:37
by sv270190
I am really sorry that I can't follow neither of the above examples
Kindly provide contents of two files for sample
And give the likely output in both the cases search term also be given
Not only myself but many fans of ahk will benefit immensely
Re: Ahk loop read file extremely slow in windows 10
Posted: 12 Dec 2016, 04:09
by garry
what you want to do ?
example reads existing file and creates a new file (?) , if a_loopreadline ... then .. goto ... (?)
Loop, Read, d:\custdet\sample.txt, d:\custdet\custdet02.rpt
FileAppend, %A_LoopReadLine%`n ; just me: added line feed
Re: Ahk loop read file extremely slow in windows 10
Posted: 18 Feb 2017, 17:30
by Mark Van
Okay, I am having great trouble getting the "loop read" command to work.
I've tried copying the examples as close to humanly possible but it just doesn't want to work.
Hopefully somebody can figure out what I'm doing wrong.
Using AutoHotKey Version 2.00 - Based on SciTE 1.77
Running it on a Windows 7 system. 64bit
Originally what I wanted to do was create a script (for testing purposes) which would read through
one file and print each line in another test file. Giving me two identical files at the end (save
for the actual names of the files). Sounds simple enough I would think.
So I wrote.
---actual code below this line---
Loop, Read, File1.txt File2.txt
{
FileAppend %A_LooReadLine%
}
---- end of code ------
Since that failed, I tried to see if I could get a different kind of loop working. Which also
failed.
---actual code below this line---
Loop, read, File1.txt, File2.txt
{
IfInString, A_LoopReadLine, Word, FileAppend, %A_LoopReadLine%`n ; "word" being a word in the
text file (and yes it is there)
}
---- end of code ------
This only creates a blank text file called Outputfile.txt. It just will not find any word in the
text file.
Above both examples I added
FileOpen(File1.txt", "r") ; for stdin
FileOpen("File2.txt", "w") ; for stdout
Because the examples seem to imply, that must be done.
It looks like the Loop Read command will not function on my machine.
Re: Ahk loop read file extremely slow in windows 10
Posted: 18 Feb 2017, 20:37
by 4GForce
Mark Van wrote:IfInString, A_LoopReadLine, Word, FileAppend, %A_LoopReadLine%`n
Code: Select all
IfInString, A_LoopReadLine, Word
{
FileAppend, %A_LoopReadLine%`n
}
Re: Ahk loop read file extremely slow in windows 10
Posted: 19 Feb 2017, 05:48
by garry
also a test example
Code: Select all
;- example-1
f1=%a_scriptdir%\TEST1.txt ;- source
f2=%a_scriptdir%\TEST2.txt ;- destination
;ifexist,%f2%
; filedelete,%f2%
searchfor=test2`,test4 ;- << in %f2% show only if found this ( test2 or test4 )
;------- for test create source-file--
ifnotexist,%f1%
{
e4x=
(Ltrim Join`r`n
Line1 test1
Line2 test2
Line3 test3
Line4 test4
Line5 test5
)
Fileappend,%e4x%,%f1%
}
;-------------------
ifexist,%f1%
{
ifnotexist,%f2%
{
Fileread,aaa,%f1%
Loop,parse,aaa,`n,`r
{
x:= a_loopfield
if x=
continue
if x contains %searchfor%
e .= x . "`r`n"
}
Fileappend,%e%,%f2%
aaa=
e=
msgbox,Created new Destination-file =`n%f2%
run,%f2%
return
}
else
{
msgbox,NOTHING done because Destination-File already exists`n%f2%
return
}
}
else
{
msgbox,NOTHING DONE because SOURCE-File NOT EXISTs =`n%f1%
return
}
return
Re: Ahk loop read file extremely slow in windows 10
Posted: 20 Feb 2017, 12:54
by Mark Van
Thanks for your help guys.
I finally managed to track down my error. When the first example failed to work I did what I usually do. Make more examples to try and narrow down where things are going wrong. Finally finding it.
I was looking at File.txt on my Windows Explorer when I realized THAT wasn't what I was looking at.
What I was really looking at was File.txt.txt
Darn stupid file extension hiding by default, screwed me up for days. Grrrrr
Well at least my computer is off the hook now. I haven't quite yet figured who to blame though. Probably end up blaming Microsoft.