السلام عليكم
هذا البرنامج يقوم بقراءة احجام ملفات ذات امتداد .LOG
و يخزن الناتج في ملف آخر على هذا الشكل:
111
222
كيف اقوم بكتابتها على هذا الشكل:
222 111
شكرا على المساعده
#include <windows.h>
main(){
WIN32_FIND_DATA fData;
HANDLE hSearch, InFile, OutFile;
char temp[MAX_PATH];
char szNewPath[MAX_PATH];
char szDirPath[] = "C:\\";
char WriteFName[] = "C:\\text\\size.txt";
DWORD size;
DWORD written;
hSearch = FindFirstFile("C:\\*.LOG",&fData);
if(hSearch == INVALID_HANDLE_VALUE)
{
MessageBox(NULL,"No .LOG files found, exiting ...","Message",MB_OK);
exit(0);
} else
{
do
{
ZeroMemory(szNewPath,MAX_PATH);
lstrcpy(szNewPath, szDirPath); // copy the directory to szNewPath c:\
lstrcat(szNewPath, fData.cFileName); // concatenate the file name with direcotry c:\file.log
MessageBox(NULL,szNewPath,"error",MB_OK);
// open an existing file
InFile = CreateFile(szNewPath, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
if(InFile == INVALID_HANDLE_VALUE)
{
MessageBox(NULL,"open file failed","error",MB_OK);
exit(0);
}
OutFile = CreateFile(WriteFName, GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if(OutFile != INVALID_HANDLE_VALUE)
{
memset(temp,0,sizeof(temp));
size = GetFileSize(InFile,NULL);
SetFilePointer(OutFile, 0, NULL, FILE_END);
if(size != 0xFFFFFFFF)
{
wsprintf(temp,"%d\r\n", size);
WriteFile(OutFile, temp, strlen(temp), &written, NULL);
}
}
} while(FindNextFile(hSearch,&fData)!= 0); // keep searching until there are no more .LOG files
} // end if
// close the handles
CloseHandle(hSearch);
CloseHandle(InFile);
}