AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   File Open and File Write (https://forums.alliedmods.net/showthread.php?t=205063)

gamer99 01-06-2013 11:38

File Open and File Write
 
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.

YamiKaitou 01-06-2013 11:43

Re: File Open and File Write
 
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

gamer99 01-06-2013 11:46

Re: File Open and File Write
 
Quote:

Originally Posted by YamiKaitou (Post 1868244)
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?

Sylwester 01-06-2013 12:03

Re: File Open and File Write
 
remove:
PHP Code:

file_handle fopen(g_sUserFile"at"


gamer99 01-06-2013 12:35

Re: File Open and File Write
 
Quote:

Originally Posted by Sylwester (Post 1868261)
remove:
PHP Code:

file_handle fopen(g_sUserFile"at"


it's not letting me edit, without that option :(

YamiKaitou 01-06-2013 12:38

Re: File Open and File Write
 
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

gamer99 01-06-2013 13:29

Re: File Open and File Write
 
ok. Can you please suggest what changes need to be done? or any link where I can check the options?

YamiKaitou 01-06-2013 13:34

Re: File Open and File Write
 
Don't use fopen twice. Simply change "wt" to "at" if that is the mode you require and then delete the second fopen line


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

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