DeleteFile

Blitz3D Forums/Blitz3D Programming/DeleteFile

Chalky(Posted 2006) [#1]
Hi all,

No matter what I try, DeleteFile steadfastly refuses to delete a file! I first use FileType and supply Path$+Filename$ (after setting Path$ via CurrentDir$() at the start of the program). Having received a "1" back from FileType, I then pass the same variables to DeleteFile but the file is never deleted:

If FileType(Path$+Filename$)=1 Then
DeleteFile Path$+Filename$
EndIf

The same things happens in Blitz Basic 2D. Can anyone please tell me what I am doing wrong? :o(


GfK(Posted 2006) [#2]
Most likely an error in the Path$ or Filename$.

Just created a folder with 'test.bb' and 'deleteme.txt' files in it.

test.bb:
DeleteFile "deleteme.txt"

Worked fine (didn't bother with error trapping because I knew for a fact that the file was there).

Try putting Path$+Filename$ into debuglog and see what it says...


big10p(Posted 2006) [#3]
I had this problem when trying to delete files from a temp folder I created in-code. I couldn't delete the temp folder because - for some reason - blitz refused to delete some files contained in it. Hmm, or was it the folder itself I couldn't delete?! Can't really remember.

Anyway, the only way I could get it to work was to do a EndGraphics before trying to delete the files! :/

Go figure.

[edit] Just checked. It was defo DeleteFile, not DeleteDir I was having the problem with. Using EndGraphics to 'fix' the prob was OK in my case because I was only deleting the temp folder when closing down the app, anyway. May not be a viable solution for you, though.


Chalky(Posted 2006) [#4]
Hmmm. Just did same as Gfk and it worked for me too - file was deleted no probs. Tried again in graphics mode (same path and file) as per big10p and blitz didn't delete it!

Weird...

Thanks for the help - at least I now know of a workaround.


RGR(Posted 2006) [#5]
.

Last edited 2012


Chalky(Posted 2006) [#6]
Hi RaGR,

Not sure why you feel the need to be insulting. I am not a beginner - I have been programming professionally for 17 years, which is why this is not in the beginner's forum. What I do not understand is that this:



works, while this:



...doesn't.

I am well aware that it could be something I have done wrong, but the deletefile above does not delete the INI file even though FileType returns 1, whereas pasting contents of Path$+"Game.ini" into VB KILL command does.

[edit]
I have just hard coded the path and filename:



and the file was not deleted. I have tested this repeatedly in debug mode and FileT% is definitely being set to 1 via FileType when BackDrop%<>0 and LoadFile$="<NONE>" [and "C:\BlitzBasic\SmallSoft\Game.ini" exists!].

Creating a new program with the code:



DID delete the file.

If you can shed any light on what I am doing wrong I would be very grateful.


GfK(Posted 2006) [#7]
You want to tell this doesn't work?
This Forum is on a good way to become a Punch and Judy show ...

Just look at those threads:
Error Opening/Closing File
Crash when leaving Screensaver
DeleteFile
Get File in String
array problam(i think so)
Save heightmap from Mesh-terrain.. Please help..

Its all in the wrong place ... Beginners is one Forum above ...
FFS, who died and made you the Forum Police?!

You seriously think the best way to welcome new Blitz users is to kick off at them like that?? You really need to sharpen up your act and get rid of the idea that everbody is beneath you. This isn't the first time you've been outright insulting to people for no justifiable reason.

Anyhoo...

Chalky - I've tried all sorts to get it to not work here, but without success.

Are you maybe trying to delete a read-only file or something? Because that's the only way I can stop DeleteFile from doing what it should...

Looking at your code above, I'd put debug Stop's in every nested 'If'. That way you'll see which bits of your code are being executed and which aren't.


Floyd(Posted 2006) [#8]
DeleteFile will also fail if the file is open.

It is fairly easy when debugging to end up with a copy of your program running in the background. In that case the file may still be in use even though you think you have closed it.


big10p(Posted 2006) [#9]
Its all in the wrong place
No it's not. It's correct to post in one of the programming forums when you think you've found a bug, so that others can confirm it before posting in the bug reports forum. Otherwise, the bug reports forum gets clogged with 'bugs' that aren't bugs at all.

I seem to remember BRL actually requested that everyone follow this protocol when reporting bugs. Unfortunately, most people don't follow it and just jump straight into the bug reports forum only to discover the 'bug' is infact a coding error on their part.

Your attitude isn't appreciated or helpful, RaGR.

Anyway, I'm going to look into this issue a bit more as I'm sure when I had the problem I wasn't forgetting to close the files before deleting them. :)

[edit]
I went back to my code I was having a similar problem with and it seems unrelated to your problem afterall, Chalky. I was messing with TTF font files which the system may have still had a handle on so wouldn't allow them to be deleted.

I tried re-creating the problem you're having (using the code you posted) and couldn't do it - the file got deleted. Maybe Floyd's points are worth checking out. I don't know what else to suggest.


Chalky(Posted 2006) [#10]
Hi all,

The fact that so many of you can get it to work is proof that it must be my coding rather than Blitz which is at fault. Guess I have an evening's serious debugging to look forward to... :0)

[edit]
Floyd - thank's a million! So much for me being a pro programmer - my INILoad function was not closing the file! I can't believe I missed that! Duh!!! :o/

Thank you all so much for your help. Much appreciated.


RFBcsa(Posted 2006) [#11]
This can happen to the best of us. Often a program gets so complicated that you might overlook even the simplest of things.

Eventhough the problem is solved I thought I might write something here the sprung into mind when reading this thread. I thought that a wait statement between creating and deleting the file might help. But not sure though...

Anyways, I am glad your problem is solved Chalky.