?? writelog.cpp
字號:
// WriteLog.cpp: implementation of the CWriteLog class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "WriteLog.h"
#include <windows.h>
#include <winbase.h>
#include <shlwapi.h>
#include <stdlib.h>
#pragma comment(lib, "shlwapi.lib")
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CWriteLog::CWriteLog()
{
}
CWriteLog::~CWriteLog()
{
}
/*************************************************************************************************************************/
/* 文件處理模塊(begin) */
/*************************************************************************************************************************/
bool CWriteLog::CheckTarPath(char *strFilePath)
{
//先判斷文件夾是否存在
if(PathFileExistsA((LPCTSTR)strFilePath))
{
return TRUE;
}
char *pFilePath = strFilePath;
char sPath[512] = {0};
while(1)
{
char *ptemp = strstr(pFilePath, "\\");
if(!ptemp)
break;
int nLen = ptemp - pFilePath;
char temp[256] = {0};
strncpy(temp, pFilePath, nLen);
if(strlen(sPath))
{
strcat(sPath, "\\");
strcat(sPath, temp);
}
else
strcat(sPath, temp);
ptemp++;
if(!ptemp)
break;
if(!PathFileExists((LPCTSTR)sPath))
{
if(!CreateFileDirectory(sPath))
return false;
}
pFilePath = ptemp;
}
return true;
}
bool CWriteLog::CreateFileDirectory(char *strPath)
{
if(CreateDirectory((LPCTSTR)strPath,NULL))
return true;
return false;
}
//寫入日志文件
bool CWriteLog::WriteLogFile(char *strFileName, char *strInfo, int nBuffer)
{
FILE *fp = NULL;
try
{
if (nBuffer<1)
return FALSE;
fp = fopen(strFileName, "a+");
if (!fp)
return false;
fwrite(strInfo, nBuffer, 1, fp);
fwrite("\r\n", strlen("\r\n"), 1, fp);
fclose(fp);
}
catch (...)
{
printf("出錯了");
DWORD err = GetLastError();
printf("error = %d", err);
if(fp)
fclose(fp);
}
if(fp)
fclose(fp);
return true;
}
/*-----------------------------------------------------------------------------------------------------------------------*/
/* 文件處理模塊(end) */
/*-----------------------------------------------------------------------------------------------------------------------*/
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -