Quote:
Originally Posted by DarthMan
Using array and the newer file system with fopen, fputs & fclose is the better way to go.
|
You don't need an array, it's totally pointless.
PHP Code:
stock RemoveLine(const FileName[], const OldLine[], const NewLine[])
{
new const TempFileName[] = "tempfile.ini"
new ConfigDirPath[128]; get_configsdir(ConfigDirPath, charsmax(ConfigDirPath))
new FullPath[256]; formatex(FullPath, charsmax(FullPath), "%s/%s", ConfigDirPath, FileName)
new FilePointer = fopen(FullPath, "rt")
if(FilePointer)
{
new TempFilePath[256]; formatex(TempFilePath, charsmax(TempFilePath), "%s/%s", ConfigDirPath, TempFileName)
new InputFilePointer = fopen(TempFilePath, "wt")
if(InputFilePointer)
{
new FileData[128]
while(!feof(FilePointer))
{
fgets(FilePointer, FileData, charsmax(FileData))
trim(FileData)
if(equal(FileData, OldLine))
{
continue
}
fprintf(InputFilePointer, "%s^n", FileData)
}
fclose(InputFilePointer)
fclose(FilePointer)
delete_file(FullPath)
rename_file(TempFilePath, FullPath, 1)
return 1
}
}
return 0
}
This is a function that I wrote in the past to remove a line from file. To replace instead of remove put a fprintf before continue with the new string.
__________________