Sometimes it is weird to encounter File not Found Error in running. But we do not know how to bypass the error. There is a line:
AHash := THash.Create();
assign(F,Getcurrentdir+'\data.txt');
reset(F);//File not Found
while not EOF(F) do
...
This(Error) is not always the case. Sometimes it prompts error, sometimes it works well.
We do not know why and how to fix it.
Thank you very much in advance.
Or is there a function to update current dir before assign the file. Will this work?
data.txt is a resource that is packaged and installed to user’s side and is permanently resided in application.exe dir. While our program is running, will the Getcurrentdir func change the actual current dir that the data.txt is located? it may not be the case.
You can check if the file exists using the
FileExists(filename) function. Its insysutils.pas.If you think the file not found error is not correct, maybe you don’t have enough rights to use the file. Or maybe the file is not on the location you expect it.
If you think the file is only sometimes “not found” due to sheer magical reasons beyond human understanding, you can use the following function. But its better to find the real reason why the file is not there when it should be there.