Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Discussion / Cannot Open File for Writing

Author
Message
Zeus
18
Years of Service
User Offline
Joined: 8th Jul 2006
Location: Atop Mount Olympus
Posted: 30th Nov 2007 23:00
When you create the dog it creates the dog's name as a directory in "media\svd_data" for some reason when I try to write a file into that directory (the dog's) I get "cannot open file for writing" here is the code,



All help appreciated,
Jordan

demons breath
21
Years of Service
User Offline
Joined: 4th Oct 2003
Location: Surrey, UK
Posted: 30th Nov 2007 23:04 Edited at: 30th Nov 2007 23:05
the file needs to be deleted before you write - are you sure you're doing that?

copy all the data out, delete the file, update the data, and write a new file with the same name as the one you just deleted.

Alternatively, save the path including the name file into a string, then just use that in the write file command.

Zeus
18
Years of Service
User Offline
Joined: 8th Jul 2006
Location: Atop Mount Olympus
Posted: 30th Nov 2007 23:34
Huh? You're not making sense.

Zeus
18
Years of Service
User Offline
Joined: 8th Jul 2006
Location: Atop Mount Olympus
Posted: 1st Dec 2007 02:09 Edited at: 1st Dec 2007 02:10
Oh come on surely someone knows.

TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 1st Dec 2007 02:24
Quote: "You're not making sense."


Makes perfect sense to me...

When you write data out to a disk file the filename you specify cannot already exist. So, you must delete the file if it is there first.

If you need the information in it, you must read it all in, delete the file, create a new one, then write out the data (including the new or changed information) - before you close the file.

The last line simply means build a string for the path and filename. That way, you can print the string to the screen so you can check for errors.

My guess is that you are trying to create the file in a folder that doesn't exist. So, if you used:

FName$ = "media\svd_data\"+name$+"\doghouseplyr.blhouse"

you could use for the Open line:

Open To Write 2,FName$

and if it doesn't work, replace the Open To Write line with:

Print FName$
Wait Key


and you can then check to see if the path printed on screen actually exists.

TDK_Man

Zeus
18
Years of Service
User Offline
Joined: 8th Jul 2006
Location: Atop Mount Olympus
Posted: 1st Dec 2007 02:55
It is reading wrong, it is reading the breed instead of the name.

TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 1st Dec 2007 22:15
Quote: "It is reading wrong, it is reading the breed instead of the name"


Then why on earth did you waste our time by saying in your first post:

Quote: "when I try to write a file into that directory (the dog's) I get "cannot open file for writing" here is the code"




TDK_Man

Zeus
18
Years of Service
User Offline
Joined: 8th Jul 2006
Location: Atop Mount Olympus
Posted: 2nd Dec 2007 15:31
The directory name was the breed's type.

Login to post a reply

Server time is: 2025-06-05 19:20:42
Your offset time is: 2025-06-05 19:20:42