Senior Member
Join Date: Jan 2018
Location: Morocco
|
10-11-2018
, 15:06
Re: Modify a file using another file
|
#7
|
Quote:
Originally Posted by Bugsy
You need to scan the files and write to a new file if your condition is met; once done, you then delete file1 and rename the new file to the file1 filename. With your code you are adding lines to the existing file.
I've always had issues with delete_file() failing. Can anyone weigh in on what the problem is? The tmpFile.tmp file is accurate regarding contents, but the deletion of the old file1 and renaming of temp to file1 fails.
PHP Code:
#include <amxmodx>
#include <amxmisc>
public plugin_init()
{
register_plugin("File Cleaner", "1.0", "~D4rkSiD3Rs~");
CleanFile();
}
public CleanFile()
{
new iFile1 , iFile2 , iFile3 , szConfigsDir[ 64 ] , szFile1[ 100 ] , szFile2[ 100 ] , szFile3[ 100 ];
new szLine1[ 36 ] , szLine2[ 36 ] , szName1[ 32 ] , szName2[ 32 ] , szOption[ 2 ];
get_configsdir( szConfigsDir , charsmax( szConfigsDir ) );
formatex( szFile1 , charsmax( szFile1 ) , "%s/TestFile1.txt" , szConfigsDir );
formatex( szFile2 , charsmax( szFile2 ) , "%s/TestFile2.txt" , szConfigsDir );
formatex( szFile3 , charsmax( szFile3 ) , "%s/tmpFile.tmp" , szConfigsDir );
iFile1 = fopen( szFile1 , "rt" );
iFile2 = fopen( szFile2 , "rt" );
iFile3 = fopen( szFile3 , "wt" );
while ( fgets( iFile1 , szLine1 , charsmax( szLine1 ) ) )
{
parse( szLine1 , szName1 , charsmax( szName1 ) );
while ( fgets( iFile2 , szLine2 , charsmax( szLine2 ) ) )
{
parse( szLine2 , szName2 , charsmax( szName2 ) , szOption , charsmax( szOption ) );
if ( equali( szName1 , szName2 ) && ( szOption[ 0 ] != '0' ) )
{
fputs( iFile3 , szLine1 );
break;
}
}
fseek( iFile2 , SEEK_SET , 0 );
}
fclose( iFile1 );
fclose( iFile2 );
fclose( iFile3 );
delete_file( szFile1 );
rename_file( szFile3 , szFile1 );
}
|
Thank you very much ^^ that helped me a lot
__________________
|
|