Un exemple coder vite fait, a toi de l'adapter a tes besoins...
DWORD __stdcall SetFileLineLength(LPSTR lpszInFile, LPSTR lpszOutFile, DWORD dwLineLength)
{
HANDLE hInFile, hOutFile;
DWORD dwRET = 1, br, bw, i, l;
LPBYTE lpData, lpIn, lpOut;
lpData = (BYTE*) HeapAlloc(GetProcessHeap(), HEAP_NO_SERIALIZE, 0x300000); // 3mo
if(!lpData) return 1;
hInFile = CreateFile(lpszInFile, GENERIC_READ, 0, 0, OPEN_EXISTING, 0, 0);
if(hInFile == INVALID_HANDLE_VALUE) goto _Error;
hOutFile = CreateFile(lpszOutFile, GENERIC_WRITE, 0, 0, CREATE_ALWAYS, 0, 0);
if(hOutFile == INVALID_HANDLE_VALUE) goto _Error;
while(1)
{
if(!ReadFile(hInFile, lpData, 0x100000, &br, 0)) goto _Error;
if(!br) break;
i = br;
l = dwLineLength;
lpIn = lpData;
lpOut = (lpData + 0x100000);
do
{
if( (*lpIn != '\r')&&(*lpIn != '\n') )
{
*lpOut++ = *lpIn;
if(!--l)
{
*((WORD*) lpOut)++ = '\r\n';
l = dwLineLength;
}
}
lpIn++;
}while(i--);
i = lpOut - (lpData+0x100000);
if(!WriteFile(hOutFile, (lpData+0x100000), i, &bw, 0)) goto _Error;
}
dwRET = 0;
_Error:
HeapFree(GetProcessHeap(), HEAP_NO_SERIALIZE, lpData);
if(hInFile) CloseHandle(hInFile);
if(hOutFile) CloseHandle(hOutFile);
return dwRET;
}
Neo_Fr
|