scripting readfile()
-
graham
- Posts: 457
- Joined: 24 Aug 2007 22:08
- Location: Isle of Man
scripting readfile()
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?
-
admin
- Site Admin
- Posts: 66347
- Joined: 22 May 2004 16:48
- Location: Win8.1, Win10, Win11, all @100%
- Contact:
Re: scripting readfile()
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?
Uh, no. (Not sure if I got the 2nd question...)
FAQ | XY News RSS | XY X
-
graham
- Posts: 457
- Joined: 24 Aug 2007 22:08
- Location: Isle of Man
Re: scripting readfile()
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.
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.
-
admin
- Site Admin
- Posts: 66347
- Joined: 22 May 2004 16:48
- Location: Win8.1, Win10, Win11, all @100%
- Contact:
Re: scripting readfile()
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.
FAQ | XY News RSS | XY X
-
jacky
- XYwiki Master
- Posts: 3106
- Joined: 23 Aug 2005 22:25
- Location: France
- Contact:
Re: scripting readfile()
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.
And if/once we'll get the ability to specify an itemslist to function report(), then obviously we'll have a file_exists function basically
Proud XYplorer Fanatic
-
TheQwerty
- Posts: 4373
- Joined: 03 Aug 2007 22:30
Re: scripting readfile()
If you just want to ensure the files exist you could use WriteFile(), but if it didn't exist you'll create it in the process.
But, like jacky, using Get/SetKey makes more sense to me.
EDIT: Don, why don't we have bitwise operators/comparison yet? Seems a bit silly to return a value that's been OR-ed, without the tools to properly dissect it.
Luckily, it only has two bits right now!
Code: Select all
$exists = WriteFile($file,"","n") > 1 ? "File Found" : "File Not Found (Until I created it just now.)");EDIT: Don, why don't we have bitwise operators/comparison yet? Seems a bit silly to return a value that's been OR-ed, without the tools to properly dissect it.
-
graham
- Posts: 457
- Joined: 24 Aug 2007 22:08
- Location: Isle of Man
Re: scripting readfile()
Jacky wrote:
Added to which, I posted the wrong copy of my script
, now hopefully corrected. I have used the this script a lot and found it a quick way to get specific access to the pdf help file.
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?
Added to which, I posted the wrong copy of my script
-
j_c_hallgren
- XY Blog Master
- Posts: 5826
- Joined: 02 Jan 2006 19:34
- Location: So. Chatham MA/Clearwater FL
- Contact:
Re: scripting readfile()
(Reusing this thread as subject/topic is very appropriate):
I'm not a scripter but based on reading a request in http://www.xyplorer.com/xyfc/viewtopic.php?f=7&t=4689, it would seem there may not be any ability in scripting to read a given amount of data from a file...that is, like the first "n" chars, so that some decisions could be made if one finds a certain value within it...
Readfile appears to read the entire file which won't work very well (if at all) for huge files but reading the first, let's say, 100 chars should be enough to know that it's a jpg file or a gif.
Is there presently a way to do this?
I'm not a scripter but based on reading a request in http://www.xyplorer.com/xyfc/viewtopic.php?f=7&t=4689, it would seem there may not be any ability in scripting to read a given amount of data from a file...that is, like the first "n" chars, so that some decisions could be made if one finds a certain value within it...
Readfile appears to read the entire file which won't work very well (if at all) for huge files but reading the first, let's say, 100 chars should be enough to know that it's a jpg file or a gif.
Is there presently a way to do this?
Still spending WAY TOO much time here! But it's such a pleasure helping XY be a treasure!
(XP on laptop with touchpad and thus NO mouse!) Using latest beta vers when possible.
(XP on laptop with touchpad and thus NO mouse!) Using latest beta vers when possible.
XYplorer Beta Club