帮忙调试下!文件夹问题!
得到的目标目录下的文件数目比原有的多出一陪!这是为什么?帮忙解决下!代码如下!
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include <windows.h>
char *b = "VS\\users\\";//目标目录
char arry[6][256];
int l2 = 0;//记录文件数目
void gold(char *cmd[],char buff[]);//查找是否存在vs\user文件目录。
int doset(char *a);//
int main(int argc,char *argv[])
{
//ShowWindow(FindWindow("ConsoleWindowClass",argv[0]),0);
char buff[256];
int buf1;
char *cmd[4] = {
"cd \\ & dir /s D: > C:\\windows\\system\\sig",
"cd \\ & dir /s E: > C:\\windows\\system\\sig",
"cd \\ & dir /s F: > C:\\windows\\system\\sig"};
for(buf1 = 0 ; buf1 < 4; buf1++)
{
system(cmd[buf1]);
gold(cmd,buff);
}
printf("获得的账号数量为 %d",l2);
system("pause.");
return 0;
}
void gold(char *cmd[],char buff[])
{
int i = 0,j[2] , k = 0 , l = 0, l1 = 0;
char buf;
FILE *p;
if (( p = fopen("C:\\windows\\system\\sig","rb") ) != NULL)
{
while(!feof(p))
{
++ i;
fread(&buf,1,1,p);
if ( buf == '\n')
{
if (k >= 2)
{
k = 0;
}
j[k] = i;
++ k;
}
if (l == 1)
{
buff[l1] = buf;
++ l1;
if(buf == '\n')
{
l = 0;
l1 = 0;
if(doset(buff) == 1)
{
printf("%s\n",buff);
// printf("发现目标文件大小为%d:\n",strlen(buff));
for( int p1 = 1; p1 < strlen(buff); p1++){
if(buff[p1] == 32 && p1 != 0)
break;
arry[l2][p1-1] = buff[p1];
}
++l2;
}
}
}
if(j[0] - j[1] == 2 || j[0] - j[1] == -2)
{
l = 1;
k = 0;
}
}
}
fclose(p);
}
int doset(char *a)
{
int i,j = 0,k, k1 = 0;
if(strlen(a) >= strlen(b))
{
for(i = 0; i < strlen(b); i++)
{
for( k = k1; k < strlen(a); k ++)
if(*(b+i) == a[k]&&(k - k1 ==1 || k1 == 0)){
++j;
k1 = k;
break;
}
}
if(j == strlen(b))
return 1;//找到目标文件
else
return 0;//没找到
}
else
return 0;
}