File not found - possible bug in Readfile/Openfile

Blitz3D Forums/Blitz3D Beginners Area/File not found - possible bug in Readfile/Openfile

Rocys(Posted 2015) [#1]
Hi there,
I'm having a problem which drives me crazy. I'd appreciate any help. Please excuse my poor english.

My program is supposed to download a bunch of files (around 2.500) from the web (works finde with CURL). The files are analyzed then via readfile.

It works pretty well for a while. But as soon as a certain number of files is analyzed, the program seems to not be able to open any new streams. Readfile allways returns 0.

The strange thing is: Filytype returns 1.

The streams are definetely closed. To make sure, I added a little code that closes the streams right before opening a new one:

[Code]

If ProfilStream><0 Then
CloseFile ProfilStream
ProfilStream=0
End If

ProfilStream=ReadFile("temp\"+DatumAktuell+"\profil_"+name+"_profil.txt")

If ProfilStream=0 Then RuntimeError ("Profil nicht gefunden: "+name)+Chr$(13)+"temp\"+DatumAktuell+"\profil_"+name+"_profil.txt"+Chr$(13)+FileType("temp\"+DatumAktuell+"\profil_"+name+"_profil.txt")

[/code]

DatumAktuell is a Global. Name is a string which is read from a different file. The error doesn't happen while reading name: the names are right and filetype returns 1.

The same error happens, when I use openfile instead of readfile. Also, if i manually skip the file which causes the error, the next file will cause the error too.

I have not the slightest idea what is going on. Can you help me? Thanks in advance!


Matty(Posted 2015) [#2]
Here's a test for you to do if you can reproduce the error.

Download the files manually.

Put them in a folder (alll 2,500 of them).

rename them with a batch program to something simple like 1.txt, 2.txt, 3.txt etc.

Run your blitz program on that simply something like:

infile = readfile(filename$)
if(infile=0) then runtimeerror("your message")
closefile infile

see if the problems happens....

I've never had an issue with it before however the problem may lie somewhere else in your code - for example if you are chewing up memory then you may get to a point where there is insufficient memory to open another file although you can verify its existence. Unlikely if things are done correctly unless you have a memory leak somewhere else.


steve_ancell(Posted 2015) [#3]
Yeah you're maxing-out your memory, just like Matty said. May be better to throttle back the amount of files downloaded at any one time, proccess and then close them one at a time, then repeat until all files are downloaded and dealt with.


Rocys(Posted 2015) [#4]
Thank you guys - you showed me the right direction.
Problem is solved.

During the loop I was not only reading the 2.500 files but also writing the results of the analysis into new files. Guess what: I forgot to close the streams from the writefile... My guess is that blitzbasic shuts down, when 1024 streams are open. I corrected the code and now it works.

Thanks again and sorry for bothering you with my inattention...


Matty(Posted 2015) [#5]
Glad it is fixed.