fremove(file) don't work.
#1

Well i'm trying to make a " rename " command for my GM but as far i know there is no "rename " function so i need to delete a file and create another one.

When i tried to code it pawno give me no errors but when i tried to make it as wiki says in this page:
https://sampwiki.blast.hk/wiki/Fremove

it gave me error for " mismatch " ...
then i tried my own and pawno did not gave any problems... but when i tried to use it IG it don't delete the file.... but i can remove it manually....

here is the code where the file soppose to be deleted:
Код:
		new fnameold[33];
		format(fnameold,sizeof(fnameold),P_FILE,udb_encode(PlayerInfo[giveplayerid][name]));
		fremove(fnameold);
This is the complete Command.
Код:
	if(strcmp(cmd, "/setname", true) == 0)
	{
  	new fname[256];
	  if(PlayerInfo[playerid][admin] == 0)
	  {
	    SendClientMessage(playerid,COLOR_BRIGHTRED,"SAC: You are not an admin to use this command!");
	    return 1;
		}
		tmp = strtok(cmdtext, idx);
		if(!IsPlayerConnected(strval(tmp)))
		{
			SendClientMessage(playerid,COLOR_BRIGHTRED,"This Player Is not Connected!");
			return 1;
		}
		if(!strlen(tmp))
		{
		  SendClientMessage(playerid,COLOR_LIGHTBLUE,"USAGE: /setname [playerid] [New PlayerName]");
		  return 1;
		}
		giveplayerid = strval(tmp);
		tmp = strtok(cmdtext, idx, strlen(cmdtext));
		if(!strlen(tmp))
		{
		  SendClientMessage(playerid,COLOR_LIGHTBLUE,"USAGE: /setname [playerid] [New PlayerName]");
		  return 1;
		}
		format(fname,sizeof(fname),P_FILE,udb_encode(tmp));
		if(fexist(fname))
		{
		  SendClientMessage(playerid,COLOR_BRIGHTRED,"This Account already Exist!");
		  return 1;
		}
		new File: file,filestring[256];
	  SetPlayerName(giveplayerid,tmp);
		GetPlayerName(giveplayerid, playername, sizeof(playername));
 		format(fname,sizeof(fname),P_FILE,udb_encode(playername));
	  file = fopen(fname, io_write);
	  if(file) {
 			format(filestring,sizeof(filestring),"%s,0,%d,0,0,500,0,0,0,0,0,0,0,0,0,0",playername,PlayerInfo[playerid][pass]);
  			fwrite(file,filestring);
	  		fclose(file);
		}
		new fnameold[33];
		format(fnameold,sizeof(fnameold),P_FILE,udb_encode(PlayerInfo[giveplayerid][name]));
		fremove(fnameold);

		format(string,sizeof(string),"SAC: You had changed the name of Player %s to %s",PlayerInfo[giveplayerid][name],tmp);
		SendClientMessage(playerid,COLOR_BRIGHTRED,string);
		format(string,sizeof(string),"SAC: Your name had been changed by admin: %s to %s",PlayerInfo[playerid][name],tmp);
		SendClientMessage(giveplayerid,COLOR_BRIGHTRED,string);
		GetPlayerName(giveplayerid, playername, sizeof(playername));
		PlayerInfo[giveplayerid][name] = playername;
		SavePlayer(giveplayerid);
	}
Reply
#2

noone knows what's wrong?
Reply
#3

Debug it and see if the filename is correct

pawn Код:
new fnameold[33];
        format(fnameold,sizeof(fnameold),P_FILE,udb_encode(PlayerInfo[giveplayerid][name]));
        printf("Removing file: |%s|", fnameold);
        fremove(fnameold);
Reply
#4

erm the file name is correct because it actually create the other file but it don't remove the other one.
Reply
#5

somebody already made a function like that, try this:
pawn Код:
stock frename(oldname[], newname[])
{
    if (!fexist(oldname)) return 0;
    new File:oldfile = fopen(oldname, io_read);
    new File:newfile = fopen(newname, io_write);
    new line[256];
    while (fread(oldfile, line))
    {
        fwrite(newfile, line);
    }
    fclose(oldfile);
    fclose(newfile);
    fremove(oldname);
    return 1;
}
Reply
#6

i tried to do that but it say " Symbol already defined frename"

Edit: nvm i fixed it with your help. tnx alot
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)