Delete file -- what am I doing wrong?

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
Timothy
Posts: 78
Joined: Tue Apr 11, 2006 7:38 pm

Delete file -- what am I doing wrong?

Post by Timothy » Mon Nov 05, 2007 5:31 am

What's wrong with this script?

The result is always "Can't delete that file."

I tried "close file" first, but the result is "file is already closed."

Code: Select all

on mouseUp
  if there is not a player 1 then
    answer "I can't find that player."
    exit mouseup
  end if
  put "delete file" && quote & the filename of player 1 & quote into tempVar
  Answer "Are you sure you want to delete" && the filename of player 1 && "?" with "Yes" or "No"
  if it is not "yes" then exit mouseUp
  do tempVar
end mouseUp

Thanks,


Tim

Klaus
Posts: 13878
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Post by Klaus » Mon Nov 05, 2007 9:27 am

Hi Timothy,

I'm not sure, but I think you cannot delete a file that is in use.
Try this (not tested, may work however :-)

Code: Select all

on mouseUp 
  if there is not a player 1 then 
    answer "I can't find that player." 
    exit mouseup 
  end if 
  put the filename of player 1 into tFilename 
  Answer "Are you sure you want to delete" && tFilename && "?" with "Yes" or "No" 
  if it is not "yes" then exit mouseUp 
  set the filename of player 1 to empty
  wait 5 millisecs
  delete file tFilename 
end mouseUp

Best

Klaus

Timothy
Posts: 78
Joined: Tue Apr 11, 2006 7:38 pm

Post by Timothy » Wed Nov 07, 2007 6:06 am

Hi Klaus, and possibly interested lurkers,

Thanks for your help.

Here's the short version of what the trouble was.

The script works, and when it works, "the result" is empty, just as it should be.

However, after the file has been deleted, the player continues to work as it did before. That's probably because the file remains in RAM until the card closes.

That caused me to wonder if the file had been deleted. So I clicked on the button again. "The result" was "can't delete that file." That caused me to conclude that the file still existed. Confusion arose.

In a perfect world, "the result" would be "File can't be found," rather than "Can't delete that file." However, this is a minor problem, at worst.

Cheers,


Tim

Post Reply

Return to “Talking LiveCode”