Hi all,
I have code like this:
put true into idNotValid
repeat while idNotValid
repeat until it is an integer
ask "What is the student ID number?"
end repeat
put It into ident
if ident is not empty then answer "Is"&&ident&&"the correct ident
number?" with "No" or "Yes"
if It is "Yes" then put false into idNotValid
end repeat
Up to here works fine. However, I want to ensure that data files do not get overwritten. I don't want to make new files read only. I just want to do a simple search to determine if there is a file with the same name already in the same directory (which will always be the same path as the running application).
I tried something like this, but to no avail...
if there is a file "R" & ident & ".txt" then answer "File already exits! Overwrite?" with "yes" or "no"
if it is "yes" then put false into fileExists
if it is "no" then put true into fileExists
if there is not a file "R" & ident & ".txt" then put false into FileExists
if fileExists then go to card "begin"
put R & ident & ".txt" into filename
Any help would be appreciated.
Josh
Preventing a data file from being overwritten
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Hi Josh,
It would be better to post the actual script rather than "code like this". The following should always work:
Best,
Mark
It would be better to post the actual script rather than "code like this". The following should always work:
Code: Select all
on foo
put "some data" into myData
ask file "Choose a file"
put it into myFile
if there is a file myFile then
answer "Really?" with "Okay" or "Cancel"
if it is "Cancel" then
exit foo
end if
else
write myData to file myFile
end if
end foo
Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode