Is there any way to programmatically catch a FileSaveAs error?
The situation I have is that I'm using the NLD script and write to a file. I open the saved file. If I write again to that same file, while it's open it can hose my original file. Yes, there's an easy work around, don't do that , but I'd like to catch the FileSaveAs error (ie it throws a dialog if you just try FileSaveAs) I'd also like to catch if the file already exists to avoid accidentally overwriting a file. However, FileSaveAs returns void
Thanks for any help.
Is the any way to catch FileSaveAs error?
Moderators: Víctor Paredes, Belgarath, slowtiger
- strider2000
- Posts: 506
- Joined: Sat Mar 07, 2015 5:14 pm
- Contact:
- hayasidist
- Posts: 3509
- Joined: Wed Feb 16, 2011 8:12 pm
- Location: Kent, England
Re: Is the any way to catch FileSaveAs error?
(sorry, don't know what the "NLD script" is) do you need to use the script interface file routines for this? LUA has file handling routines that will trap errors.
(I use LM.GUI.SaveFile to get the path name, then the lua io.xxx and file:xxx routines - http://www.lua.org/manual/5.2/manual.html#6.8 - once I've got the desired filename - e.g. as in this: http://www.kelleytown.com/forum/animato ... IC_ID=1431)
(I use LM.GUI.SaveFile to get the path name, then the lua io.xxx and file:xxx routines - http://www.lua.org/manual/5.2/manual.html#6.8 - once I've got the desired filename - e.g. as in this: http://www.kelleytown.com/forum/animato ... IC_ID=1431)
- strider2000
- Posts: 506
- Joined: Sat Mar 07, 2015 5:14 pm
- Contact:
Re: Is the any way to catch FileSaveAs error?
Sorry, for the confusion. The NLD script is the No Limits Designer script by Mike Kelly. It's calling the script Interface routine. You bring up a good point I can check out the standard lua file handling and your link. Thanks
- synthsin75
- Posts: 9968
- Joined: Mon Jan 14, 2008 11:20 pm
- Location: Oklahoma
- Contact:
Re: Is the any way to catch FileSaveAs error?
At least on Windows, moho:FileSaveAs() just uses to OS dialog, so the OS should notify you if overwriting.
You can see if a file exists using:
local test = io.open(path, "rb")
If (test) then
--the file exists
io.close(test)
end
Make sure to close the file (io.close), if it exists.
I think if you save to an open file you typically need to reopen the file to see the changes.
You can see if a file exists using:
local test = io.open(path, "rb")
If (test) then
--the file exists
io.close(test)
end
Make sure to close the file (io.close), if it exists.
I think if you save to an open file you typically need to reopen the file to see the changes.
- Wes
Donations: https://www.paypal.com/paypalme/synthsin75 (Thx, everyone.)
https://www.youtube.com/user/synthsin75
Scripting reference: https://mohoscripting.com/
Donations: https://www.paypal.com/paypalme/synthsin75 (Thx, everyone.)
https://www.youtube.com/user/synthsin75
Scripting reference: https://mohoscripting.com/
- hayasidist
- Posts: 3509
- Joined: Wed Feb 16, 2011 8:12 pm
- Location: Kent, England
Re: Is the any way to catch FileSaveAs error?
should have thought of that!!! (just didn't make the connection in the context of you seeming to want to update a script)strider2000 wrote:Sorry, for the confusion. The NLD script is the No Limits Designer script by Mike Kelly. It's calling the script Interface routine.