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 Professional Discussion / How to save a text file?

Author
Message
Mark Garrett
Reviewed AGK on Steam
20
Years of Service
User Offline
Joined: 10th Jul 2005
Location: California, US
Posted: 11th Jun 2014 07:43 Edited at: 11th Jun 2014 07:49
How do I save a text file? I have been looking for a 'save' command in DB-Pro, but I have not found any command like that.

Here's what I have so far.... I'm copying from 'text file 1' to 'text file 2'. So after that, how do I save 'text file 2'?


.
TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 11th Jun 2014 08:15 Edited at: 11th Jun 2014 08:16
You're already doing it correctly. You're writing the string "a$" to text file 2, and when you call "close file 2", the file is guaranteed to be saved.

Probably a better way is to read until "file end" returns true:



Mark Garrett
Reviewed AGK on Steam
20
Years of Service
User Offline
Joined: 10th Jul 2005
Location: California, US
Posted: 11th Jun 2014 09:00 Edited at: 12th Jun 2014 19:00
I tried using your code, but both files fail to open. What could I be doing wrong?



.
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 11th Jun 2014 13:24 Edited at: 11th Jun 2014 13:28
That code works perfectly here. Perhaps your file is in the wrong folder? Check the file exists before trying to open it by using the file exist() function.

Edit On reflection that can't be the problem because DBPro will give an error if the file isn't there. Strange. Might be worth trying anyway just in case.



Powered by Free Banners
TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 11th Jun 2014 21:03
If files fail to open, it could be because:
1) Your disk is full
2) You don't have write permissions

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 11th Jun 2014 22:34
Quote: "2) You don't have write permissions"


Good point. I guess a simple test of that would be to simply try to open a new file and nothing else.



Powered by Free Banners
MrValentine
AGK Backer
15
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 11th Jun 2014 23:28
If the file exists already, for Open To Write, it will fail, you must delete any file you will write to with that command...

So an ideal solution is probably open to read a file, read its contents entirely say to an array or such and then write the entire array to the new file...

That is if you are writing to the same file...

But yeah, if the Open To Write file exists, check that it exists first with File Exist() and then delete it with Delete File()

Mark Garrett
Reviewed AGK on Steam
20
Years of Service
User Offline
Joined: 10th Jul 2005
Location: California, US
Posted: 12th Jun 2014 19:02 Edited at: 12th Jun 2014 19:03
Thanks, I will try that, good advice from all of you.

.
Phaelax
DBPro Master
23
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 17th Jun 2014 03:34

Login to post a reply

Server time is: 2026-07-06 11:07:34
Your offset time is: 2026-07-06 11:07:34