New topic: 

file deletion not working

<http://forums.realsoftware.com/viewtopic.php?t=30602>

       Page 1 of 1
   [ 3 posts ]                 Previous topic | Next topic         Author  
Message       azrael2000           Post subject: file deletion not 
workingPosted: Thu Oct 22, 2009 10:49 am                               
Joined: Fri Oct 13, 2006 3:18 pm
Posts: 251              Hi All.

This is frikkin driving me nuts.

The code I have below, doesn't consistantly delete my "Allergies" file.  I have 
redone the code, stepped through, haven't gotten a LastError code, but it still 
won't get rid of the flipping file.

I thought it was due to permissions, but even on a machine (several actually) 
where I am an admin / root, it happens.

Perhaps someone can look at this and see what I am missing?


Code:'find the file and make it go bye bye...
'this makes the folderitem disappear

'now clear out the EditFields
'and yes, as I said in earlier comments, there is a better way to do it. but 
this is the way I'm doing it now.
wMain.EditField1.text = ""
wMain.EditField2.text = ""
wMain.EditField3.text = ""
wMain.EditField4.text = ""
wMain.EditField5.text = ""
wMain.EditField6.text = ""
wMain.EditField7.text = ""
wMain.EditField8.text = ""
wMain.EditField9.text = ""
wMain.EditField10.text = ""
wMain.EditField11.text = ""
wMain.EditField12.text = ""
wMain.EditField13.text = ""
wMain.ccAlert1.StaticText1.text = "Hamaliel Software" //this resets the alert 
to the company name

f=GetFolderItem("PetInformation") //choose where the pet information is kept
f.delete //get rid of it

f=GetFolderItem("Shots") //choose where the shots are kept
f.Delete //get rid of it
wMain.lstShots.DeleteAllRows 'now clear out the Shots information

f=GetFolderItem("Allergies") //select file
f.delete //delete
wMain.lstAllergy.DeleteAllRows //get rid of any info in the listbox

'what I will have to do here is build a file with a default picture (in this 
case, baby bandit...)
'for now, however...

f=GetFolderItem("PetPicture") //choose where the picture is kept
if f.exists=false then //verify that there is a file called pet picture...
  MsgBox "No New Pet Picture"
  wDeleteAlert.close
else
  tis =f.OpenAsTextFile
  holding =tis.readline
  tis.close // don't frikkin forget this! You don't, the file can't be deleted 
because it is in use!
end if

f=GetFolderItem("").child("pictures").child(holding) //selects the specific file
f.delete //deletes the file

f=GetFolderItem("PetPicture") //selects the file
f.delete // deletes it

'this line puts Baby's picture in; however it does not recreate PetPicture item
f=GetFolderItem("").child("pictures").child("babyd.jpg") //the default picture
mypic = f.OpenAsPicture
wMain.Canvas1.Refresh


Regards   
                            Top                Phil M           Post subject: 
Re: file deletion not workingPosted: Thu Oct 22, 2009 11:34 am                  
      
Joined: Fri Sep 30, 2005 12:18 pm
Posts: 190              Are you sure you aren't getting any error codes?  Just 
to verify, put "If ( f.LastErrorCode <> 0 ) Then MsgBox Str( f.LastErrorCode )" 
after each f.Delete line.

Looks like your code is correct as long as the app can find the files to begin 
with.  The syntax you are using assumes the file will be in the current 
directory which usually means the same folder your application is launched 
from.  Its usually better to store information like this in a known place such 
as SpecialFolder.ApplicationData and create a folder for your app.  Another 
good place is the SpecialFolder.Preferences (again make a folder for your app).

Unless a FolderItem's parent (path or object) is non-existant, FolderItem 
returns a valid object even if the file DOESN'T exist (and no error) because 
FolderItem has no idea if you are going to be creating a new file with that 
name or open or delete.  To verify that the FolderItem actually exists, check 
"If f.Exists Then"...   
                            Top               azrael2000           Post 
subject: Re: file deletion not workingPosted: Thu Oct 22, 2009 12:06 pm         
                      
Joined: Fri Oct 13, 2006 3:18 pm
Posts: 251              Hi there.

I think I found the problem.

It wasn't in the deletion, but in the creation.  I had the db.close command, 
but for some reason it was not being done.

I re-entered the command, and now it seems to be working.

And yes, for some strange reason I did not get any f.lasterrorcode. I'm going 
to dig a little more into the coding issue.

But thanks for your help.

Regards   
                            Top            Display posts from previous: All 
posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost 
timeSubject AscendingDescending          Page 1 of 1
   [ 3 posts ]     
-- 
Over 1500 classes with 29000 functions in one REALbasic plug-in collection. 
The Monkeybread Software Realbasic Plugin v9.3. 
http://www.monkeybreadsoftware.de/realbasic/plugins.shtml

[email protected]

Reply via email to