Preventing a data file from being overwritten
Posted: Mon Feb 04, 2008 8:21 am
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
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