Linux下掌握(統計)文件的生成的C代碼完成。本站提示廣大學習愛好者:(Linux下掌握(統計)文件的生成的C代碼完成)文章只能為提供參考,不一定能成為您想要的結果。以下是Linux下掌握(統計)文件的生成的C代碼完成正文
本文分享了Linux下掌握(統計)文件的生成的C代碼完成案例,供年夜家參考,詳細內容以下
1、需求描寫
不准時地在Linux機械下的某目次中放入文件,文件內容中包括了用戶號碼、起止時光等字段,現請求編寫一法式來統計今朝該目次中一切文件中的記載總條數及一切記載中的最夙興始時光和最晚停止時光。
例如,該目次中有兩個文件Test_1.txt和Test_2.txt,個中Test_1.txt文件內容為:
Test_2.txt文件內容為:
即文件中的每筆記錄的格局為:呼喚號碼|被呼喚號碼|呼喚肇端時光|呼喚停止時光|,請求生成的掌握文件CtlFile.txt的內容為:
即Test_1.txt和Test_2.txt兩個文件中五筆記錄的開端時光的最小值為“20151101 110909”,停止時光的最年夜值為“20160109 091545”,今朝共處置了5筆記錄。也就是說,掌握文件的格局為:呼喚肇端時光最小值|呼喚停止時光最年夜值|記載總條數|。
2、法式代碼
本法式一共包含了三個代碼文件:main.c、CtlFileCreate.c和CtlFileCreate.h,詳細代碼以下:
main.c
/**********************************************************************
* 版權一切 (C)2016, Zhou Zhaoxiong。
*
* 文件稱號:CtlFileCreate.c
* 文件標識:無
* 內容摘要:目次中文件的讀取及掌握文件的生成
* 其它解釋:無
* 以後版本:V1.0
* 完成日期:20160109
*
**********************************************************************/
#include "CtlFileCreate.h"
/**********************************************************************
* 功效描寫:主函數
* 輸出參數:無
* 輸入參數:無
* 返 回 值:無
* 其它解釋:無
* 修正日期 版本號 修正人 修正內容
* -------------------------------------------------------------------
* 20160109 V1.0 Zhou Zhaoxiong 創立
***********************************************************************/
INT32 main()
{
ReadCtlFile(); // 獲得掌握文件寄存途徑、掌握文件全途徑名及文件內容字段值
ReadSrcFileAndWriteCtlFile(); // 掃描源文件目次, 並寫掌握文件
return 0;
}
CtlFileCreate.h
/**********************************************************************
* 版權一切 (C)2015, Zhou Zhaoxiong。
*
* 文件稱號:CtlFileCreate.h
* 文件標識:無
* 內容摘要:目次中文件的讀取及掌握文件的生成
* 其它解釋:無
* 以後版本:V1.0
* 完成日期:20151102
*
**********************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <dirent.h>
// 數據類型重界說
typedef unsigned char UINT8;
typedef unsigned short int UINT16;
typedef unsigned int UINT32;
typedef signed int INT32;
typedef unsigned char BOOL;
// 參數類型
#define MML_INT8_TYPE 0
#define MML_INT16_TYPE 1
#define MML_INT32_TYPE 2
#define MML_STR_TYPE 3
#define TRUE (BOOL)1
#define FALSE (BOOL)0
// 字段最年夜長度
#define MAX_RET_BUF_LEN 1024
// 源文件字段構造體
typedef struct
{
UINT8 szSrcNumber[50];
UINT8 szDstNumber[50];
UINT8 szDataStartTime[50];
UINT8 szDataEndTime[50];
} T_SrcFileContent;
// 函數聲明
void Sleep(UINT32 iCountMs);
void ReadCtlFile(void);
void ReadSrcFileAndWriteCtlFile(void);
void GetSrcFileContentAndWriteCtlFile(UINT8 *pszSrcFileName);
void GetSrcFileFieldValue(UINT8 *pszContentLine, T_SrcFileContent *ptSrcFileContent);
void GetCtlFileContentAndWrite(T_SrcFileContent *ptSrcFileContent, UINT8 *pszContentBuffer);
BOOL GetValueFromStr(UINT16 iSerialNum, UINT8 iContentType, UINT8 *pSourceStr, UINT8 *pDstStr, UINT8 cIsolater, UINT32 iDstStrSize);
void RemoveLineEnd(UINT8 *pszStr);
void WriteToCtlFile(UINT8 *pszContentLine);
CtlFileCreate.c
/**********************************************************************
* 版權一切 (C)2015, Zhou Zhaoxiong。
*
* 文件稱號:CtlFileCreate.c
* 文件標識:無
* 內容摘要:目次中文件的讀取及掌握文件的生成
* 其它解釋:無
* 以後版本:V1.0
* 完成日期:20151102
*
**********************************************************************/
#include "CtlFileCreate.h"
// 全局變量
UINT8 g_szSourceDir[500] = {0}; // 需掃描的源目次
UINT8 g_szCtlFileDir[500] = {0}; // 生成的掌握文件的寄存目次
UINT8 g_szSourceBakDir[500] = {0}; // 處置以後的源文件的備份目次
UINT8 g_szCtlFileName[256] = {0}; // 掌握文件全途徑名
UINT8 g_szDataStartTime[50] = {0}; // 一切源文件中數據記載的最早開端時光
UINT8 g_szDataEndTime[50] = {0}; // 一切源文件中數據記載的最晚停止時光
UINT32 g_iRecordsSum = 0; // 已處置的記載的總條數
/**********************************************************************
* 功效描寫: 讀取掌握文件中的開端時光、停止時光和記載條數
* 輸出參數: 無
* 輸入參數: 無
* 返 回 值: 無
* 其它解釋: 無
* 修正日期 版本號 修正人 修正內容
* ------------------------------------------------------------------
* 20151102 V1.0 Zhou Zhaoxiong 創立
********************************************************************/
void ReadCtlFile(void)
{
UINT8 *pszHomePath = NULL;
FILE *fpCtlFile = NULL;
UINT8 szBuf[500] = {0};
// 讀取掌握文件中的開端時光、停止時光和記載條數, 假如是當天法式重啟, 則記載條數持續編號
pszHomePath = getenv("HOME");
if (pszHomePath == NULL)
{
return;
}
snprintf(g_szCtlFileDir, sizeof(g_szCtlFileDir)-1, "%s/zhouzhaoxiong/zzx/CtlFileCreate/CtlFile", pszHomePath); // 掌握文件寄存目次
snprintf(g_szCtlFileName, sizeof(g_szCtlFileName)-1, "%s/CtlFile.txt", g_szCtlFileDir); // 掌握文件全途徑名
fpCtlFile = fopen(g_szCtlFileName, "r");
if (fpCtlFile != NULL)
{
fgets(szBuf, sizeof(szBuf), fpCtlFile);
// 獲得開端時光g_szDataStartTime
if (TRUE != GetValueFromStr(1, MML_STR_TYPE, szBuf, g_szDataStartTime, '|', sizeof(g_szDataStartTime)))
{
printf("ReadCtlFile: exec GetValueFromStr to get g_szDataStartTime failed!\n");
return;
}
// 獲得停止時光g_szDataEndTime
if (TRUE != GetValueFromStr(2, MML_STR_TYPE, szBuf, g_szDataEndTime, '|', sizeof(g_szDataEndTime)))
{
printf("ReadCtlFile: exec GetValueFromStr to get g_szDataEndTime failed!\n");
return;
}
// 獲得記載條數g_iRecordsSum
if (TRUE != GetValueFromStr(3, MML_INT32_TYPE, szBuf, (UINT8 *)&g_iRecordsSum, '|', sizeof(g_iRecordsSum)))
{
printf("ReadCtlFile: exec GetValueFromStr to get g_iRecordsSum failed!\n");
return;
}
fclose(fpCtlFile);
fpCtlFile = NULL;
printf("ReadCtlFile: DataStartTime=%s, DataEndTime=%s, RecordsSum=%d\n", g_szDataStartTime, g_szDataEndTime, g_iRecordsSum);
}
}
/**********************************************************************
* 功效描寫: 掃描源文件目次, 並寫掌握文件
* 輸出參數: 無
* 輸入參數: 無
* 返 回 值: 無
* 其它解釋: 無
* 修正日期 版本號 修正人 修正內容
* ------------------------------------------------------------------
* 20151102 V1.0 Zhou Zhaoxiong 創立
********************************************************************/
void ReadSrcFileAndWriteCtlFile(void)
{
UINT8 *pszHomePath = NULL;
UINT8 szCommandBuf[500] = {0};
UINT8 szSrcFile[500] = {0};
DIR *pDir = NULL;
struct dirent *pDirent = NULL;
pszHomePath = getenv("HOME");
if (pszHomePath == NULL)
{
return;
}
snprintf(g_szSourceDir, sizeof(g_szSourceDir)-1, "%s/zhouzhaoxiong/zzx/CtlFileCreate/SrcFile", pszHomePath); // 源文件寄存目次
snprintf(g_szSourceBakDir, sizeof(g_szSourceBakDir)-1, "%s/zhouzhaoxiong/zzx/CtlFileCreate/SrcFile_bak", pszHomePath); // 源文件備份目次
while (1)
{
pDir = opendir(g_szSourceDir);
if (NULL == pDir)
{
printf("ReadSrcFileAndWriteCtlFile: pDir is NULL!\n");
continue;
}
while ((pDirent = readdir(pDir)) != NULL) // 掃描源目次, 獲得文件名
{
if (strncmp(pDirent->d_name, "Test_", strlen("Test_")) == 0) // 假如婚配上了源文件的前綴, 則讀取文件內容並寫掌握文件
{
memset(szSrcFile, 0x00, sizeof(szSrcFile));
snprintf(szSrcFile, sizeof(szSrcFile)-1, "%s/%s", g_szSourceDir, pDirent->d_name, g_szSourceBakDir);
GetSrcFileContentAndWriteCtlFile(szSrcFile); // 獲得源文件中的內容, 並寫掌握文件
// 處置完成以後, 將文件剪切到備份目次中
memset(szCommandBuf, 0x00, sizeof(szCommandBuf));
snprintf(szCommandBuf, sizeof(szCommandBuf)-1, "mv %s %s", szSrcFile, g_szSourceBakDir);
system(szCommandBuf);
printf("ReadSrcFileAndWriteCtlFile: now, move %s to %s\n", pDirent->d_name, g_szSourceBakDir);
}
}
closedir(pDir);
pDir = NULL;
Sleep(60 * 1000); // 每1分鐘掃描一次
}
}
/**********************************************************************
* 功效描寫: 獲得源文件中的內容, 並寫掌握文件
* 輸出參數: pszSrcFileName-領路徑的源文件名
* 輸入參數: 無
* 返 回 值: 無
* 其它解釋: 無
* 修正日期 版本號 修正人 修正內容
* ------------------------------------------------------------------
* 20151102 V1.0 Zhou Zhaoxiong 創立
********************************************************************/
void GetSrcFileContentAndWriteCtlFile(UINT8 *pszSrcFileName)
{
FILE *fp = NULL;
UINT8 szContentLine[1024] = {0};
T_SrcFileContent tSrcFileContent = {0};
if (pszSrcFileName == NULL)
{
printf("GetSrcFileContentAndWriteCtlFile: pDir is NULL!\n");
return;
}
if ((fp = fopen(pszSrcFileName, "r")) == NULL) // 只讀方法翻開
{
printf("GetSrcFileContentAndWriteCtlFile: open src file failed!\n");
return;
}
else
{
while (feof(fp) == 0 && ferror(fp) == 0)
{
// 每行對應一條源文件記載
memset(szContentLine, 0x00, sizeof(szContentLine));
if (fgets(szContentLine, sizeof(szContentLine), fp) == NULL)
{
printf("GetSrcFileContentAndWriteCtlFile: exec fgets to get line null.\n");
}
else
{
printf("GetSrcFileContentAndWriteCtlFile: get content line: %s\n", szContentLine);
}
RemoveLineEnd(szContentLine); // 去失落字符串前面的回車換行符
if (strlen(szContentLine) == 0) // 假如為空行, 則持續處置下一條
{
printf("GetSrcFileContentAndWriteCtlFile: the length of ContentLine is 0, continue.\n");
continue;
}
GetSrcFileFieldValue(szContentLine, &tSrcFileContent); // 獲得一筆記錄中各個字段的值
memset(szContentLine, 0x00, sizeof(szContentLine));
GetCtlFileContentAndWrite(&tSrcFileContent, szContentLine); // 組裝寫入掌握文件中的內容
WriteToCtlFile(szContentLine); // 將內容寫到掌握文件中
}
fclose(fp);
fp = NULL;
}
}
/**********************************************************************
* 功效描寫: 組裝寫入掌握文件中的內容
* 輸出參數: ptSrcFileContent-源文件中一筆記錄中各個字段的值
* 輸入參數: pszContentBuffer-寄存內容的緩存
* 返 回 值: 無
* 其它解釋: 掌握文件中記載為: DataStartTime|DataEndTime|RecordsSum|
* 修正日期 版本號 修正人 修正內容
* ------------------------------------------------------------------
* 20151102 V1.0 Zhou Zhaoxiong 創立
********************************************************************/
void GetCtlFileContentAndWrite(T_SrcFileContent *ptSrcFileContent, UINT8 *pszContentBuffer)
{
UINT8 szContentLine[500] = {0};
if (ptSrcFileContent == NULL || pszContentBuffer == NULL)
{
printf("GetCtlFileContentAndWrite: ptSrcFileContent or pszContentBuffer is NULL!\n");
return;
}
// 依據值的年夜小對g_szDataStartTime停止賦值
if (strlen(g_szDataStartTime) == 0) // 當天第一條
{
strncpy(g_szDataStartTime, ptSrcFileContent->szDataStartTime, strlen(ptSrcFileContent->szDataStartTime));
}
else
{
if (strncmp(g_szDataStartTime, ptSrcFileContent->szDataStartTime, strlen(ptSrcFileContent->szDataStartTime)) > 0) // 修正成最小時光
{
memset(g_szDataStartTime, 0x00, sizeof(g_szDataStartTime));
strncpy(g_szDataStartTime, ptSrcFileContent->szDataStartTime, strlen(ptSrcFileContent->szDataStartTime));
}
}
// 依據值的年夜小對g_szDataEndTime停止賦值
if (strlen(g_szDataEndTime) == 0) // 當天第一條
{
strncpy(g_szDataEndTime, ptSrcFileContent->szDataEndTime, strlen(ptSrcFileContent->szDataEndTime));
}
else
{
if (strncmp(g_szDataEndTime, ptSrcFileContent->szDataEndTime, strlen(ptSrcFileContent->szDataEndTime)) < 0) // 修正成最年夜時光
{
memset(g_szDataEndTime, 0x00, sizeof(g_szDataEndTime));
strncpy(g_szDataEndTime, ptSrcFileContent->szDataEndTime, strlen(ptSrcFileContent->szDataEndTime));
}
}
// 記載總條數加1
g_iRecordsSum = g_iRecordsSum + 1; // 當天一切記載的總條數加1
// 打印三個字段的內容
printf("GetCtlFileContentAndWrite: DataStartTime is %s, DataEndTime is %s, RecordsSum is %d\n", g_szDataStartTime, g_szDataEndTime, g_iRecordsSum);
// 組裝寫到掌握文件中的新聞內容
snprintf(szContentLine, sizeof(szContentLine)-1, "%s|%s|%d|", g_szDataStartTime, g_szDataEndTime, g_iRecordsSum);
printf("GetCtlFileContentAndWrite: ContentLine is %s\n", szContentLine);
strncpy(pszContentBuffer, szContentLine, strlen(szContentLine));
}
/**********************************************************************
* 功效描寫: 獲得源文件中的各個字段的值
* 輸出參數: pszContentLine-一筆記錄
* 輸入參數: ptSrcFileContent-源文件中一筆記錄中各個字段的值
* 返 回 值: 無
* 其它解釋: 源文件中每筆記錄的格局為: SrcNumber|DstNumber|DataStartTime|DataEndTime|
* 修正日期 版本號 修正人 修正內容
* ------------------------------------------------------------------
* 20151102 V1.0 Zhou Zhaoxiong 創立
********************************************************************/
void GetSrcFileFieldValue(UINT8 *pszContentLine, T_SrcFileContent *ptSrcFileContent)
{
if (pszContentLine == NULL || ptSrcFileContent == NULL)
{
printf("GetSrcFileFieldValue: ContentLine or SrcFileContent is NULL!\n");
return;
}
// 獲得源號碼
if (TRUE != GetValueFromStr(1, MML_STR_TYPE, pszContentLine, ptSrcFileContent->szSrcNumber, '|', sizeof(ptSrcFileContent->szSrcNumber)))
{
printf("GetSrcFileFieldValue: exec GetValueFromStr to get szSrcNumber failed!\n");
return;
}
// 獲得目標號碼
if (TRUE != GetValueFromStr(2, MML_STR_TYPE, pszContentLine, ptSrcFileContent->szDstNumber, '|', sizeof(ptSrcFileContent->szDstNumber)))
{
printf("GetSrcFileFieldValue: exec GetValueFromStr to get szDstNumber failed!\n");
return;
}
// 獲得開端時光
if (TRUE != GetValueFromStr(3, MML_STR_TYPE, pszContentLine, ptSrcFileContent->szDataStartTime, '|', sizeof(ptSrcFileContent->szDataStartTime)))
{
printf("GetSrcFileFieldValue: exec GetValueFromStr to get szDataStartTime failed!\n");
return;
}
// 獲得停止時光
if (TRUE != GetValueFromStr(4, MML_STR_TYPE, pszContentLine, ptSrcFileContent->szDataEndTime, '|', sizeof(ptSrcFileContent->szDataEndTime)))
{
printf("GetSrcFileFieldValue: exec GetValueFromStr to get szDataEndTime failed!\n");
return;
}
printf("GetSrcFileFieldValue: SrcNumber=%s, DstNumber=%s, DataStartTime=%s, DataEndTime=%s\n", ptSrcFileContent->szSrcNumber, ptSrcFileContent->szDstNumber,
ptSrcFileContent->szDataStartTime, ptSrcFileContent->szDataEndTime);
}
/**********************************************************************
* 功效描寫: 法式休眠
* 輸出參數: iCountMs-休眠時光(單元:ms)
* 輸入參數: 無
* 返 回 值: 無
* 其它解釋: 無
* 修正日期 版本號 修正人 修正內容
* ------------------------------------------------------------------
* 20151102 V1.0 Zhou Zhaoxiong 創立
********************************************************************/
void Sleep(UINT32 iCountMs)
{
struct timeval t_timeout = {0};
if (iCountMs < 1000)
{
t_timeout.tv_sec = 0;
t_timeout.tv_usec = iCountMs * 1000;
}
else
{
t_timeout.tv_sec = iCountMs / 1000;
t_timeout.tv_usec = (iCountMs % 1000) * 1000;
}
select(0, NULL, NULL, NULL, &t_timeout); // 挪用select函數壅塞法式
}
/**********************************************************************
*功效描寫:獲得字符串中某一個字段的值
*輸出參數:iSerialNum-字段編號(為正整數)
iContentType-須要獲得的內容的類型
pSourceStr-源字符串
pDstStr-目標字符串(提取的值的寄存地位)
cIsolater-源字符串中字段的分隔符
iDstStrSize-目標字符串的長度
*輸入參數:無
*返 回 值:TRUE-勝利 FALSE-掉敗
*其它解釋:無
*修正日期 版本號 修正人 修正內容
* --------------------------------------------------------------
* 20151102 V1.0 Zhou Zhaoxiong 創立
***********************************************************************/
BOOL GetValueFromStr(UINT16 iSerialNum, UINT8 iContentType, UINT8 *pSourceStr, UINT8 *pDstStr, UINT8 cIsolater, UINT32 iDstStrSize)
{
UINT8 *pStrBegin = NULL;
UINT8 *pStrEnd = NULL;
UINT8 szRetBuf[MAX_RET_BUF_LEN] = {0}; // 截掏出的字符串放入該數組中
UINT8 *pUINT8 = NULL;
UINT16 *pUINT16 = NULL;
UINT32 *pUINT32 = NULL;
UINT32 iFieldLen = 0; // 用於表現每一個字段的現實長度
if (pSourceStr == NULL) // 對輸出指針的異常情形停止斷定
{
return FALSE;
}
//字段首
pStrBegin = pSourceStr;
while (--iSerialNum != 0)
{
pStrBegin = strchr(pStrBegin, cIsolater);
if (pStrBegin == NULL)
{
return FALSE;
}
pStrBegin ++;
}
//字段尾
pStrEnd = strchr(pStrBegin, cIsolater);
if (pStrEnd == NULL)
{
return FALSE;
}
iFieldLen = (UINT16)(pStrEnd - pStrBegin);
if(iFieldLen >= MAX_RET_BUF_LEN) //停止異常掩護, 避免每一個字段的值太長
{
iFieldLen = MAX_RET_BUF_LEN - 1;
}
memcpy(szRetBuf, pStrBegin, iFieldLen);
//將須要的字段值放到pDstStr中去
switch (iContentType)
{
case MML_STR_TYPE: //字符串類型
{
strncpy(pDstStr, szRetBuf, iDstStrSize);
break;
}
case MML_INT8_TYPE: //字符類型
{
pUINT8 = (UINT8 *)pDstStr;
*pDstStr = (UINT8)atoi(szRetBuf);
break;
}
case MML_INT16_TYPE: // short int類型
{
pUINT16 = (UINT16 *)pDstStr;
*pUINT16 = (UINT16)atoi(szRetBuf);
break;
}
case MML_INT32_TYPE: // int類型
{
pUINT32 = (UINT32 *)pDstStr;
*pUINT32 = (UINT32)atoi(szRetBuf);
break;
}
default: // 必定要有default分支
{
return FALSE;
}
}
return TRUE;
}
/**********************************************************************
* 功效描寫: 去失落字符串前面的回車換行符
* 輸出參數: pszStr-輸出的字符串
* 輸入參數: 無
* 返 回 值: 無
* 其它解釋: 無
* 修正日期 版本號 修正人 修正內容
* ------------------------------------------------------------------
* 20151102 V1.0 Zhou Zhaoxiong 創立
********************************************************************/
void RemoveLineEnd(UINT8 *pszStr)
{
UINT32 iStrLen = 0;
if (pszStr == NULL)
{
printf("RemoveLineEnd: pszStr is NULL!\n");
return;
}
iStrLen = strlen(pszStr);
while (iStrLen > 0)
{
if (pszStr[iStrLen-1] == '\n' || pszStr[iStrLen-1] == '\r')
{
pszStr[iStrLen-1] = '\0';
}
else
{
break;
}
iStrLen --;
}
return;
}
/**********************************************************************
* 功效描寫: 把內容寫到掌握文件中
* 輸出參數: pszContentLine-一條則件記載
* 輸入參數: 無
* 返 回 值: 無
* 其它解釋: 無
* 修正日期 版本號 修正人 修正內容
* ------------------------------------------------------
* 20151103 V1.0 Zhou Zhaoxiong 創立
***********************************************************************/
void WriteToCtlFile(UINT8 *pszContentLine)
{
FILE *fpCtlFile = NULL;
if (pszContentLine == NULL)
{
printf("WriteToCtlFile: pszContentLine is NULL.\n");
return;
}
fpCtlFile = fopen(g_szCtlFileName, "w");
if (fpCtlFile != NULL)
{
fputs(pszContentLine, fpCtlFile);
fclose(fpCtlFile);
fpCtlFile = NULL;
printf("WriteToCtlFile: write ctl file successfully! file=%s, content=%s\n", g_szCtlFileName, pszContentLine);
}
else
{
printf("WriteToCtlFile: write ctl file failed! file=%s, content=%s\n", g_szCtlFileName, pszContentLine);
}
}
3、法式編譯及運轉
將法式代碼上傳到Linux機械上,並在以後用戶的zhouzhaoxiong/zzx/CtlFileCreate/SrcFile目次下上傳一些知足定名標准的源文件,然後應用“gcc -g -o CtlFileCreate main.c CtlFileCreate.c”敕令對法式停止編譯,生成“CtlFileCreate”文件;接著運轉“CtlFileCreate”敕令,可以看到在以後用戶的zhouzhaoxiong/zzx/CtlFileCreate/CtlFile目次下有掌握文件生成,在以後用戶的zhouzhaoxiong/zzx/CtlFileCreate/SrcFile_bak目次下有源文件的備份文件生成。
檢查掌握文件內容,外面記載的就是以後所處置的一切文件中的記載總條數及一切記載中的呼喚肇端時光最小值和呼喚停止時光最年夜值。
4、法式解釋
第一,為了便於解釋,在本法式中,源文件的前綴是“Test_”,掌握文件定名為“CtlFile.txt”。在現實的開辟中,年夜家完整可以經由過程設置裝備擺設項來決議源文件及掌握文件的定名規矩。
第二,為了避免源文件被反復處置,當某個源文件處置完成以後,會被剪切到備份目次中。如許做也是為了便利以後校訂掌握文件中的內容。
第三,在讀取文件中的第一筆記錄時,將該筆記錄中的呼喚肇端時光和呼喚停止時光分離寄存到兩個全局變量中,並依照格局寫掌握文件;在讀取該文件中的其他記載時,起首將該筆記錄中的呼喚肇端時光和呼喚停止時光與全局變量停止比擬,確保全局變量中寄存的是呼喚肇端時光最小值和呼喚停止時光最年夜值,記載總條數加1,並將新的記載內容寫入到掌握文件中。
第四,在處置完以後目次下的一切文件以後,法式會休眠一段時光,然後持續掃描目次。在現實的開辟中,休眠距離也是可以設置裝備擺設的。
以上就是本文的全體內容,願望對年夜家的進修有所贊助。