The file doesn't get deleted (Notes app)

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

The file doesn't get deleted (Notes app)

Postby vlad-x » Sun Apr 02, 2017 11:27 pm

I followed the "Notes" lessons and everything seems to work.

Except for the "delete" option. Files don't get deleted. Please see the code below.

Could it be because of the Windows permissions? If yes, how can I make it work?

Thank you
Vlad

<><><><><><><><><><>

-- Sent to the card when it is opened
-- Make any updates to the card and do any setup before the card is shown
on preOpenCard
-- Declare any local variables
local tFilePath

-- if the "noteName" field is empty then start a new note
if the label of widget "header" is empty then
newNote
else
-- if the "noteName" field is not empty then
-- get the full path to the note file
put noteFilename() into tFilePath

-- display the contents of the note file in the "noteText" field
put url ("file:" & tFilePath) into field "noteText"
end if
end preOpenCard

--
-- newNote
-- DESCRIPTION:
-- Prepare the card for a new note
-- Empty the "noteName" and "noteText" fields
-- Display the current date in the "date" field
--
command newNote
-- Clear the "noteName" and "noteText" fields
set the label of widget "header" to empty
put empty into field "noteText"

-- Display the current date in the "date" field
put the long system date into field "date"
end newNote

--
-- saveNote
-- DESCRIPTION:
-- Saves the note out to a text file
-- If there is no content in the note nothing is saved
-- Otherwise a file is created in the notes folder,
-- The name of the file is the first 15 characters of the note text
-- After the note is saved go to the "list" card
--
command saveNote
-- Declare any local variables
local tFilePath

-- Check that there is text in the note
if field "noteText" is not empty then
-- Get the full path to the note file
put noteFilename() into tFilePath

-- Save the text to the file
put field "noteText" into url ("file:" & tFilePath)
end if

-- Go to the "list" card using a transition animation
visual effect "push" right fast
go to card "list"
end saveNote

--
-- deleteNote
-- DESCRIPTION:
-- Deletes a note by deleting the file it is saved in
-- Asks for confirmation from the user that the note is to be deleted
-- After the note is deleted go to the "list" card
--
command deleteNote
-- Declare any local variables
local tFilePath

-- Ask for confirmation from the user
answer "Do you want to delete this note?" With "Yes" and "No"
if it is "Yes" then
-- Get the full path to the note file
put noteFilename() into tFilePath

-- Delete the file the note is saved in
delete file tFilePath
end if

-- Go to the "list" card using a transition animation
visual effect "push" right fast
go to card "list"
end deleteNote

--
-- noteFilename
-- DESCRIPTION:
-- Returns the full path to the file a note is saved in
--
function noteFilename
-- Declare any local variables
local tFilePath, tFileName

-- If the "noteName" field is empty
-- then the first 15 characters of the note text are used as the name of the file
if the label of widget "header" is empty then
put character 1 to 15 of field "noteText" & ".txt" into tFileName
else
-- Otherwise the current name is used
put the label of widget "header" & ".txt" into tFileName
end if

-- Construct the full path to the file
put notesFolder() & "/" & tFileName into tFilePath

-- Return the full path
return tFilePath
end noteFilename
vlad-x
 
Posts: 10
Joined: Sat Mar 18, 2017 12:32 am

Re: The file doesn't get deleted (Notes app)

Postby jmburnod » Mon Apr 03, 2017 9:03 am

Hi Vlad
I just read this:
Code: Select all
   put notesFolder() & "/" & tFileName into tFilePath

It seems there is not notesFolder function
Best regards
Jean-Marc
jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
 
Posts: 1876
Joined: Sat Dec 22, 2007 5:35 pm
Location: Genève

Re: The file doesn't get deleted (Notes app)

Postby vlad-x » Mon Apr 03, 2017 3:41 pm

notesFolder function is there... just in a different file.

Any other ideas?

Thank you!
vlad-x
 
Posts: 10
Joined: Sat Mar 18, 2017 12:32 am

Re: The file doesn't get deleted (Notes app)

Postby FourthWorld » Mon Apr 03, 2017 4:06 pm

Hello Vlad -

I took the liberty of deleting the duplicate thread for this issue so we can keep replies in one place. Going forward please do not create duplicate threads. I think you'll find most regulars here use the "New Posts" link near the top of the front page, so they'll find your post no matter where it is. If you'd like to move a post to a section you feel is a better fit, just let me know and I can do that.

As for your issue, the most common way to handle non-termination errors in LiveCode is to check the value of "the result" immediately after the command in question.

So in your case, try:
Code: Select all
delete file tFilePath
if the result is not empty then
      answer "Couldn't delete file (" & sysError() &")"
      exit to top
end if

There "the result" will be empty on success, and if it fails it'll contain a string something like "couldn't delete file". The additional call to the sysError function will query the OS for the specific error code related to the failure.

Once you know why the delete command is failing, we can determine options for handling that.
Richard Gaskin
Community volunteer LiveCode Community Liaison

LiveCode development, training, and consulting services: Fourth World Systems: http://FourthWorld.com
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/
FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
 
Posts: 5242
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles

Re: The file doesn't get deleted (Notes app)

Postby vlad-x » Mon Apr 03, 2017 11:34 pm

Thank you! :)
vlad-x
 
Posts: 10
Joined: Sat Mar 18, 2017 12:32 am


Return to Notes

Who is online

Users browsing this forum: No registered users and 1 guest