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.

Newcomers DBPro Corner / File Commands Question

Author
Message
unjust
21
Years of Service
User Offline
Joined: 25th May 2003
Location:
Posted: 5th Dec 2003 05:32
Is there any way to open a file that already exists and write data into that file?
the_winch
21
Years of Service
User Offline
Joined: 1st Feb 2003
Location: Oxford, UK
Posted: 5th Dec 2003 13:49 Edited at: 5th Dec 2003 13:50
Unfortunatly there isn't even an append method in db.
You need to read the file, modify or add to the data then delete the file and write all the info out again.
Or if you just want to append read the file and write directly to another file then append your data, delete the original file and rename the new file to the original file.

Or use a dll.
The coding area recently wrote a dll that provides random access to files.
see
http://www.thegamecreators.com/?m=forum_view&t=21115&b=5
I have never used it but it looks like you might need to know the C methods for reading/writing to files.

dbpro : p166mmx @ 233 : 256mb : sb 128pci : sis onboard
OSX Using Happy Dude
21
Years of Service
User Offline
Joined: 21st Aug 2003
Location: At home
Posted: 5th Dec 2003 15:21
Yes, indeed - I can list them if your interested.
It will let you append data to the end of a file, or if you so wish elsewhere.


Mirrors are more fun than television. Well, that was fun, in a not-so-fun sort of way...
X_MEN
21
Years of Service
User Offline
Joined: 14th Sep 2003
Location:
Posted: 5th Dec 2003 23:10
TRY MY FUNCTION

You can do it if you try
OSX Using Happy Dude
21
Years of Service
User Offline
Joined: 21st Aug 2003
Location: At home
Posted: 6th Dec 2003 01:27
Or you could try mine :

handle=fopen("file","ab",_SH_DENYWR)
x=fprint(handle,"This will be added to the end of a file")
fclose(handle)


Mirrors are more fun than television. Well, that was fun, in a not-so-fun sort of way...
unjust
21
Years of Service
User Offline
Joined: 25th May 2003
Location:
Posted: 6th Dec 2003 03:05 Edited at: 6th Dec 2003 03:07
Thanks for the replies. I have a few questions about TCA's dll for file I/O. I downloaded the keywords200.ini file and Memory.dll. I am not sure I understand everything going on with it. If you have a help file for the commands you created I think I can figure it out. I am wondering if it is possible to search the file for a string$ then write data into the file after the string$.

Let me explain what I am doing. I have a server program running supporting clients who log in and would recieve either a default position for new players, or the last position if they were previous users. OPEN TO READ gives me this data. Logging out the client envokes SaveGameState(User) where I need to open a file on the server, find the User's name, write their data, then close the file. the_winch's idea had passed through my head, but I really need to save as much processing power as possible for other more dubious tasks. This is a bit of a letdown for me from DBPro. I thought the MAKEFILE command would create a file and OPEN TO WRITE would take an existing file and add data to it. Was I ever surprised!

Anyway, I appreciate the input and will check back later.
OSX Using Happy Dude
21
Years of Service
User Offline
Joined: 21st Aug 2003
Location: At home
Posted: 6th Dec 2003 15:13
Quote: "help file for the commands "

Help and I aren't on speaking (or typing terms)...

I dont have a search string option - might be worth adding though. However, it does sound as though you would have an easier time using INI files.

Anyhoo - the mode commands for fopen are (there is also an example on my web site) :

"r"
Opens for reading. If the file does not exist or cannot be found, the fopen call fails.
"w"
Opens an empty file for writing. If the given file exists, its contents are destroyed.
"a"
Opens for writing at the end of the file (appending); creates the file first if it does not exist.
"r+"
Opens for both reading and writing. (The file must exist.)
"w+"
Opens an empty file for both reading and writing. If the given file exists, its contents are destroyed.
"a+"
Opens for reading and appending; creates the file first if it does not exist.
Use the "w" and "w+" types with care, as they can destroy existing files.

When a file is opened with the "a" or "a+" access type, all write operations occur at the end of the file. The file pointer can be repositioned using fseek, but is always moved back to the end of the file before any write operation is carried out. Thus existing data cannot be overwritten. When the "r+", "w+", or "a+" access type is specified, both reading and writing are allowed (the file is said to be open for "update"). However, when switching between reading and writing, there must be an intervening fsetpos, fseek, or rewind operation. The current position can be specified for the fsetpos or fseek operation, if desired. In addition to the above values, one of the following characters can be included in mode to specify the translation mode for new lines:

t
Opens a file in text (translated) mode. In this mode, carriage return–linefeed (CR-LF) combinations are translated into single linefeeds (LF) on input and LF characters are translated to CR-LF combinations on output. Also, CTRL+Z is interpreted as an end-of-file character on input. In files opened for reading or reading/writing, _fsopen checks for a CTRL+Z at the end of the file and removes it, if possible. This is done because using fseek and ftell to move within a file that ends with a CTRL+Z may cause fseek to behave improperly near the end of the file.

b
Opens a file in binary (untranslated) mode; the above translations are suppressed.

The share mode options are :

_SH_DENYNO
Permits read and write access.
_SH_DENYRD
Denies read access to file.
_SH_DENYRW
Denies read and write access to file.
_SH_DENYWR
Denies write access to file.


Mirrors are more fun than television. Well, that was fun, in a not-so-fun sort of way...

Login to post a reply

Server time is: 2024-11-25 19:52:22
Your offset time is: 2024-11-25 19:52:22