Raised This Month: $ Target: $400
 0% 

File Open and File Write


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
gamer99
Senior Member
Join Date: Jul 2011
Old 01-06-2013 , 11:38   File Open and File Write
Reply With Quote #1

Hi..

I did this
PHP Code:
public rewrite_user_file()
{
    new 
sBuffer[128]
    new 
file_handle fopen(g_sUserFile"wt")
    
file_handle fopen(g_sUserFile"at")
    new 
dSize=ArraySize(g_sAdminFile)
    for(new 
i;i<dSize;i++)
    {
        
ArrayGetString(g_sAdminFile,i,sBuffer,charsmax(sBuffer))
        
formatex(sBuffercharsmax(sBuffer), "%s^n",sBuffer)
        
fputs(file_handlesBuffer)
    }
    
fclose(file_handle)

It's doing it's job perfectly but I am having one problem. When server is running, and I am trying to manually modify the file "g_sUserFile" I am getting the error
"The file is being used by another process" and it's not letting me edit the file manually. What I did wrong here? Please suggest.
__________________
Thanks and regards,
Gamer99
gamer99 is offline
YamiKaitou
Has a lovely bunch of coconuts
Join Date: Apr 2006
Location: Texas
Old 01-06-2013 , 11:43   Re: File Open and File Write
Reply With Quote #2

It is the nature of Windows. Until the other process releases the lock on the file, no other processes can touch it. There is nothing you can do except to have your plugin (and any other plugins reading the file) close and release the handle on the file
__________________
ProjectYami Laboratories

I do not browse the forums regularly anymore. If you need me for anything (asking questions or anything else), then PM me (be descriptive in your PM, message containing only a link to a thread will be ignored).
YamiKaitou is offline
gamer99
Senior Member
Join Date: Jul 2011
Old 01-06-2013 , 11:46   Re: File Open and File Write
Reply With Quote #3

Quote:
Originally Posted by YamiKaitou View Post
It is the nature of Windows. Until the other process releases the lock on the file, no other processes can touch it. There is nothing you can do except to have your plugin (and any other plugins reading the file) close and release the handle on the file
I am closing the file_handle..

PHP Code:
 fclose(file_handle
Anything more need to be done in order to close/release it?
__________________
Thanks and regards,
Gamer99
gamer99 is offline
Sylwester
Veteran Member
Join Date: Oct 2006
Location: Poland
Old 01-06-2013 , 12:03   Re: File Open and File Write
Reply With Quote #4

remove:
PHP Code:
file_handle fopen(g_sUserFile"at"
__________________
Impossible is Nothing
Sylwester is offline
gamer99
Senior Member
Join Date: Jul 2011
Old 01-06-2013 , 12:35   Re: File Open and File Write
Reply With Quote #5

Quote:
Originally Posted by Sylwester View Post
remove:
PHP Code:
file_handle fopen(g_sUserFile"at"
it's not letting me edit, without that option
__________________
Thanks and regards,
Gamer99
gamer99 is offline
YamiKaitou
Has a lovely bunch of coconuts
Join Date: Apr 2006
Location: Texas
Old 01-06-2013 , 12:38   Re: File Open and File Write
Reply With Quote #6

So then modify this line with the correct options
PHP Code:
new file_handle fopen(g_sUserFile"wt"
If you haven't figured it out yet, you are opening the file twice but only closing one of them, so Windows believes it is still open and in use
__________________
ProjectYami Laboratories

I do not browse the forums regularly anymore. If you need me for anything (asking questions or anything else), then PM me (be descriptive in your PM, message containing only a link to a thread will be ignored).
YamiKaitou is offline
gamer99
Senior Member
Join Date: Jul 2011
Old 01-06-2013 , 13:29   Re: File Open and File Write
Reply With Quote #7

ok. Can you please suggest what changes need to be done? or any link where I can check the options?
__________________
Thanks and regards,
Gamer99

Last edited by gamer99; 01-06-2013 at 13:30.
gamer99 is offline
YamiKaitou
Has a lovely bunch of coconuts
Join Date: Apr 2006
Location: Texas
Old 01-06-2013 , 13:34   Re: File Open and File Write
Reply With Quote #8

Don't use fopen twice. Simply change "wt" to "at" if that is the mode you require and then delete the second fopen line
__________________
ProjectYami Laboratories

I do not browse the forums regularly anymore. If you need me for anything (asking questions or anything else), then PM me (be descriptive in your PM, message containing only a link to a thread will be ignored).
YamiKaitou is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 13:39.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode