C 删除在目录下文件名 在索引文件内容中不存在的文件

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include<io.h>

void DeleteFile(char  *pcFileName, char* acContent);
int main(void)
{
 _finddata_t file; 
 long lf; 
 char acFileName[260];
 FILE *pMapFile = NULL;
 char acContent[1024000];
 memset(acContent, 0, 1024000);

 pMapFile = fopen("reference.ditamap", "r");
 if (NULL == pMapFile)
 {
  printf("reference.ditamap open fail!\n");
 }
 int iRet = fread(acContent,1,1024000, pMapFile);
 if (0 == iRet)
 {
  printf("fread err\n");
 }
 //输入文件夹路径 d:\\OSG\\Data\\*.*  
 //lf = _findfirst("D:\\PLT-1.1-mml-help\\MML-help-new-svn\\ForHelpXml\\00-chinese\\lte\\复件 mml\\*.*", &file);
 lf = _findfirst("*.*", &file);
 if(-1 == lf) 
 {
  printf("Not Found!\n"); 
 }
 else
 { 
  //输出文件名  
  while(0 == _findnext( lf, &file))
  {   
   DeleteFile(file.name, acContent);
  } 
 } 
 _findclose(lf); 
 fclose(pMapFile);
 return 0;
}

void DeleteFile(char  *pcFileName, char* acContent)
{
 char* pLocate = NULL;
 int iEql = -1;
 char *psNotDelFile[] ={"..", ".svn" ,"Debug", "main.cpp", "reference.ditamap" ,
           "test3.vcproj...user", "test3.vcproj",};
 int iFileNum = sizeof(psNotDelFile)/sizeof(psNotDelFile[0]);
 for (int iLp=0; iLp<iFileNum; iLp++)
 {
  iEql = strcmp(psNotDelFile[iLp], pcFileName);
  if (0 == iEql)
  {
   return ;
  }
 }
 
 pLocate = strstr(acContent, pcFileName);
 if (!pLocate)
 {//没找到该文件
  printf("%s\n",pcFileName);
  int iRet = remove(pcFileName);
  if (iRet)
  {
   printf("Delete fail\n");
  }
  else
  {
   printf("Delete succes\n");
  }
 } 
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值