fremove bug
#1

File is not deleted after executing the command
no clue why
Anyone ?
PHP Code:
CMD:clearbans(playerid)
{
    if(!
IsAuth(playerid6)) return NoAuth(playerid);
    
fremove("bans.cfg");
    new 
File:file fopen("bans.cfg"io_readwrite);
    
fclose(file);
    new 
string[128];
    
format(stringsizeof(string), "AdmCmd: %s %s has cleared the ban list, therefore, everyone have been unbanned."RPARN(playerid), RPN(playerid));
    
Log("unban.log"string);
    
SendAMessage(1string);
    return 
1;

Reply
#2

Maybe the file "ban.cfg" isn't existing in your scriptfiles.
You can only remove files from the scriptfiles folder.
Reply
#3

maybe you need to remove this
PHP Code:

   
new File:file fopen("bans.cfg"io_readwrite); 
    
fclose(file); 
Reply
#4

Quote:
Originally Posted by Slawiii
View Post
maybe you need to remove this
PHP Code:

   
new File:file fopen("bans.cfg"io_readwrite); 
    
fclose(file); 
No. If fremove doesn't work, maybe the file doesn't exist or the path is wrong.
Reply
#5

Quote:
Originally Posted by Dayrion
View Post
No. If fremove doesn't work, maybe the file doesn't exist or the path is wrong.
The file surely exists, the script checks it under OnFilterScriptInit and creates it if it's not
I also checked the scriptfiles folders step by step when I tested this command

the fopen is meant to create it back, since I only want to delete the content, not the file itself
Reply
#6

PHP Code:
CMD:clearbans(playerid)
{
    if(!
IsAuth(playerid6)) return NoAuth(playerid);
    
    
// Create the file on OnGameModeInit() using io_append instead of io_write. By doing this you don't need to check if the file exist before this command executes.
    
    
new
        
File:handle fopen("bans.cfg"io_write), // io_write deletes the entire data in the file. No need to use fremove.
        
string[128];
        
    if(
handle// Valid handle
    
{
        
fclose(handle); // Close the file. Data has been deleted.
        
        
format(stringsizeof(string), "AdmCmd: %s %s has cleared the ban list, therefore everyone has been unbanned."RPARN(playerid), RPN(playerid));
        
Log("unban.log"string);
        
SendAMessage(1string);
    }
    else 
// We must check this, just in case.
    
{
        
format(stringsizeof(string), "Admin %s %s tried to erase the data of ban.cfg. There's been an error while deleting the data."RPARN(playerid), RPN(playerid));
        
Log("unban.log"string);
        
        print(string);
        
SendClientMessage(playerid, -1">> There has been an error while deleting the ban file. Report the server's owner.");
    }
    return 
1;

Reply
#7

Quote:
Originally Posted by Jf
View Post
PHP Code:
CMD:clearbans(playerid)
{
    if(!
IsAuth(playerid6)) return NoAuth(playerid);
    
    
// Create the file on OnGameModeInit() using io_append instead of io_write. By doing this you don't need to check if the file exist before this command executes.
    
    
new
        
File:handle fopen("bans.cfg"io_write), // io_write deletes the entire data in the file. No need to use fremove.
        
string[128];
        
    if(
handle// Valid handle
    
{
        
fclose(handle); // Close the file. Data has been deleted.
        
        
format(stringsizeof(string), "AdmCmd: %s %s has cleared the ban list, therefore everyone has been unbanned."RPARN(playerid), RPN(playerid));
        
Log("unban.log"string);
        
SendAMessage(1string);
    }
    else 
// We must check this, just in case.
    
{
        
format(stringsizeof(string), "Admin %s %s tried to erase the data of ban.cfg. There's been an error while deleting the data."RPARN(playerid), RPN(playerid));
        
Log("unban.log"string);
        
        print(string);
        
SendClientMessage(playerid, -1">> There has been an error while deleting the ban file. Report the server's owner.");
    }
    return 
1;

Modified it a bit but works, thanks
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)