John_Miller@mindlink.UUCP (John Miller) (01/31/91)
John Kevin Calhoun writes > The "save" command in HyperCard 2.0 does what you want. Examples: > > save this stack as "Fred" > save stack "Template" as "The stack I'm going to work with" A problem with the "save stack" command is that it fails if the a file already exists with the name given. There doesn't seem to be any magical keywords such as "with overwrite" or "with extreme prejudice" to cause it to overwrite a file that already exists. Consider a common use: saving a stack to a file that has been specified by the user. ask file "Dump scripts to" with "Scripts in stack Bob" if the result is empty then save this stack as it if the result is not empty then answer the result end if end if If the stack "Scripts in stack Bob" already exists, the standard file package has already asked "Are you really, really sure you want to replace this file?". Yet the script will fail with a "Can't duplicate stack" result. For the case where the file being overwritten is a stack, more elaborate scripting can be used to get the desired effect: ask file "Dump scripts to" with "Scripts in stack Bob" if the result is empty then put it into stackCopy if there is a stack stackCopy then -- Who knows what evil lurks in messages set the lockMessages to true set the lockRecent to true lock screen go stack stackCopy domenu "Delete Stack..." without dialog go back end if -- possibly unlock messages, recent, and screen at this point save this stack as stackCopy if the result is not empty then answer the result end if end if Unfortunately, this doesn't handle the standard Macintosh behaviour where the file being overwritten can be any type of file. Unless I'm missing something, in order to deal with the case where the existing "Scripts in stack Bob" is a non-stack file, I still have to use a "delete file" XCMD. > Org. : Apple Computer Inc., Cupertino, CA > Person: John Kevin Calhoun By the way, I must compliment your parents on their impeccable taste in names. :) ---------------------------------------------------------------------- John Kevin Miller (604) 433-1795 Symplex Systems AppleLink (rarely) CDA0461 Burnaby, British Columbia Fax: (604) 430-8516 Canada usenet: john_miller@mindlink.uucp ----------------------------------------------------------------------
lee@quincy.cs.umass.edu (Peter &) (02/05/91)
In article <1991Feb4.054700.2881@fennel.cc.uwa.oz.au> n_hays@fennel.cc.uwa.oz.au writes: From: n_hays@fennel.cc.uwa.oz.au Newsgroups: comp.sys.mac.hypercard Date: 3 Feb 91 21:47:00 GMT References: <4646@mindlink.UUCP> Organization: University of Western Australia In article <4646@mindlink.UUCP>, John_Miller@mindlink.UUCP (John Miller) writes: > John Kevin Calhoun writes >> The "save" command in HyperCard 2.0 does what you want. Examples: >> > save this stack as "Fred" >> save stack "Template" as "The stack I'm going to work with" > > A problem with the "save stack" command is that it fails > if the a file already exists with the name given. There > doesn't seem to be any magical keywords such as "with > overwrite" or "with extreme prejudice" to cause it to > overwrite a file that already exists > > ---------------------------------------------------------------------- > John Kevin Miller (604) 433-1795 > Symplex Systems AppleLink (rarely) CDA0461 > Burnaby, British Columbia Fax: (604) 430-8516 > Canada usenet: john_miller@mindlink.uucp > ---------------------------------------------------------------------- Sounds like what you might need is the "File Exists" XFCN. As the name suggests it tests whether or not a file exists given a full pathname. You could then quizz the user in Hypertalk as to whether or not they want to overwrite the file and use one of the various "delete file" XCMD's if they do, or just automatically add a "1" to the name otherwise. "FileExists" is a part of the Support Tools eXternals 1.2.5 package which (I think?) is available on apple.com. Neale **************************************************************************** Neale Hays n_hays@fennel.cc.uwa.oz.au The University of Western Australia **************************************************************************** I don't think this XFCN is necessary in HC 2.0 -- you should be able to say: if there is a stack "blah" then ... -- |- Peter E. Lee, Staff Assistant -| | Software Development Lab at the University of Massachusetts at Amherst | | lee@cs.umass.edu or Fuligin@umass.bitnet or (413) 256-1329 | "When you expect whistles, it's flutes. When you expect flutes, it's whistles"
jdevoto@Apple.COM (Jeanne A. E. DeVoto) (02/05/91)
In article <1991Feb4.054700.2881@fennel.cc.uwa.oz.au> n_hays@fennel.cc.uwa.oz.au writes in reply to John Miller: >> A problem with the "save stack" command is that it fails >> if the a file already exists with the name given. There >> doesn't seem to be any magical keywords such as "with >> overwrite" or "with extreme prejudice" to cause it to >> overwrite a file that already exists > >Sounds like what you might need is the "File Exists" XFCN. As the name >suggests it tests whether or not a file exists given a full pathname. >You could then quizz the user in Hypertalk as to whether or not they >want to overwrite the file and use one of the various "delete file" >XCMD's if they do, or just automatically add a "1" to the name otherwise. Actually, you don't need FileExists any more, since 2.0 has an operator "there is". if there is a file "Unknown Magnanimity:Stuff:Gigs:CI$" then beep if there is a card button "foo" if there is a card ID 22314 if there is not a window "My Palette" if there is no menuItem "Paste" of menu "Edit" you get the idea. This very handy operator doesn't seem very well known. -- ========= jeanne a. e. devoto ======================================== jdevoto@apple.com | You may not distribute this article under a jdevoto@well.sf.ca.us | compilation copyright without my permission. ______________________________________________________________________ Apple Computer and I are not authorized | CI$: 72411,165 to speak for each other. |
bayes@hplvec.LVLD.HP.COM (Scott Bayes) (02/06/91)
> Sounds like what you might need is the "File Exists" XFCN. As the name > suggests it tests whether or not a file exists given a full pathname. > You could then quizz the user in Hypertalk as to whether or not they > want to overwrite the file and use one of the various "delete file" > XCMD's if they do, or just automatically add a "1" to the name otherwise. > "FileExists" is a part of the Support Tools eXternals 1.2.5 package > which (I think?) is available on apple.com. > > Neale > > **************************************************************************** > Neale Hays > n_hays@fennel.cc.uwa.oz.au The University of Western Australia > **************************************************************************** Watch out on networks, or in multi-tasking environments. In my own OS, I've seen cases where fileExists returns false, but when I go to create the new file, I get an error due to some user or task creating the file after the existence test, before my create. You really need an atomic operation, like createIfNotExisting, or createAndReportSuccess. Scott "they pay me to think of stuff like this" Bayes
n_hays@fennel.cc.uwa.oz.au (02/06/91)
In article <48829@apple.Apple.COM>, jdevoto@Apple.COM (Jeanne A. E. DeVoto) writes: > > Actually, you don't need FileExists any more, since 2.0 has an operator > "there is". > > if there is a file "Unknown Magnanimity:Stuff:Gigs:CI$" then beep > if there is a card button "foo" > if there is a card ID 22314 > if there is not a window "My Palette" > if there is no menuItem "Paste" of menu "Edit" > > you get the idea. This very handy operator doesn't seem very well known. > -- > ========= jeanne a. e. devoto ======================================== > jdevoto@apple.com | You may not distribute this article under a > jdevoto@well.sf.ca.us | compilation copyright without my permission. > ______________________________________________________________________ > Apple Computer and I are not authorized | CI$: 72411,165 > to speak for each other. | Does anyone know of a "Convert brain to Hypercard 2.0" XCMD? :-) Neale ***************************************************************************** Neale Hays n_hays@fennel.cc.uwa.oz.au The University of Western Australia *****************************************************************************