Problem saving files

Sarah Reichelt sarah.reichelt at gmail.com
Tue Jul 6 01:50:45 EDT 2010


On Tue, Jul 6, 2010 at 3:22 PM, David C. <davidocoker at gmail.com> wrote:
> I've run into a bit of a head scratching problem with saving files
> that maybe someone can help me sort out.
> My code:
>
> on SaveTheFile
>   ask file "Save project as:" with filter "MYFL file,*.myfl"
>   if it <> "" then
>      put it into tfile
>      put fld "save list" into tFiletoSave
>      put tFileToSave into url ("file:" &  tfile & ".myfl")
>   else
>      exit to top
>   end if
>  end SaveTheFile
>
>  The file saves exactly as expected *if* there isn't a file with the same name.
>  Example from code above, the filename written would be: myfilename.myfl
>
> If there is a file with the same name, it correctly asks if I want to
> replace it, but when I click yes, instead of overwriting the file
> properly, it still creates a new file, but with the extension doubled
> up, as in: myfilename.myfl.myfl
>
> The other ways I've tried to code it, it still does the "do you want
> to replace" routine and will overwrite the file without doubling up on
> the extension, *but* it won't automatically add the proper extension
> to a new file.


I have never used filter with the ask command, but here is what I
think is happening:

When you ask for a file, if a new file name is types in, you get just
the name with no extension.
If you select an existing file, then you get the filename PLUS it's extension.
Your script then adds the extension regardless, so extensions will accumulate.

You need to add a check to see if the file extension is already there,
and only append it to the file name if it is missing.

Cheers,
Sarah

Rodeo discussion:
http://rodeoapps.com/rodeo-discuss-among-yourselves



More information about the Use-livecode mailing list