scripting readfile()
Posted: 15 Jan 2009 18:27
Is it possible to test a return value for success or not of the function? Also, is the test bit in scripting 3 to provide and easy path to a sub?
Forum for XYplorer Users and Developers
https://www.xyplorer.com/xyfc/
No.graham wrote:Is it possible to test a return value for success or not of the function? Also, is the test bit in scripting 3 to provide and easy path to a sub?
I personally could not live without a function ExistFile(), so why not simply add it to XY scripting? Any objections (comments) anybody?graham wrote:ok to be more specific - in the script I posted to give pdf help file access I use readfile() to get the paths of files used subsequently, however, if not found (when run first time) the script gives a scripting error. Pressing continue at that stage causes the script to continue which proceeds to request input and then creates and writes the file.
So what I want is the ability in scripting to avoid the visible error message and go to the sub which handles a file not found condition.
hmm... I'm not sure this is possible right now, but why don't you simply use an INI file (with getkey/setkey) to store your settings, instead of using readfile()? Calling getkey on a non-existing file doesn't throw any error (nor does it create an empty file, just returns an empty string) so that should allow you to do what you need, no?graham wrote:ok to be more specific - in the script I posted to give pdf help file access I use readfile() to get the paths of files used subsequently, however, if not found (when run first time) the script gives a scripting error. Pressing continue at that stage causes the script to continue which proceeds to request input and then creates and writes the file.
So what I want is the ability in scripting to avoid the visible error message and go to the sub which handles a file not found condition.
Code: Select all
$exists = WriteFile($file,"","n") > 1 ? "File Found" : "File Not Found (Until I created it just now.)");Yes you are right but, I wanted to try out using a specific file since we have read and write file then surely one should be able to test if a file exists. I think such a function existfile() as Don has mentioned could open up a lot of possibilities when processing text and other data in scripts.hmm... I'm not sure this is possible right now, but why don't you simply use an INI file (with getkey/setkey) to store your settings, instead of using readfile()? Calling getkey on a non-existing file doesn't throw any error (nor does it create an empty file, just returns an empty string) so that should allow you to do what you need, no?