In my previous posts, i have tried to explain about Recursive File reading in Windows operating systems. But some chages are required to run the program in Windows CE. The program as follows:
void Function()
{
WIN32_FIND_DATA FileData;
HANDLE hSearch;
static RetValue=1;
unsigned char DirPath[300];
unsigned char DirPath_Temp[300];
unsigned int Count=0;
unsigned int Temp=0,Temp_2=0;
unsigned char Temp1[300];
unsigned char *Paths[300];
unsigned int Completed=0;
lstrcpy(DirPath,L"\\windows\\*.*");
Completed = 0;
hSearch = FindFirstFile(DirPath, &FileData);
while(1)
{
if(FileData.dwFileAttributes == 16 && RetValue != 0)
{
RetValue=1;
printf("directory is %S\n", FileData.cFileName);
Paths[Count] = (char*)malloc(300);
if(!Paths[Count])
{
printf("Malloc failed\n");
return -1;
}
Temp = lstrlen(DirPath);
Temp = Temp*2;
if(DirPath[Temp-2] == '*')
{
Temp = Temp - 6;
}
Temp_2 = 0;
while(Temp)
{
Temp1[Temp_2] = DirPath[Temp_2];
Temp_2++;
Temp--;
}
Temp1[Temp_2]='\0';
Temp1[Temp_2+1]='\0';
lstrcat(Temp1,FileData.cFileName);
lstrcat(Temp1,"\\");
lstrcpy(Paths[Count], Temp1);
Count++;
}
else if(FileData.dwFileAttributes == 32 && RetValue != 0)
{
RetValue=1;
Temp = lstrlen(DirPath);
Temp = Temp*2;
if(DirPath[Temp-2] == '*')
{
Temp = Temp - 6;
}
Temp_2 = 0;
while(Temp)
{
Temp1[Temp_2] = DirPath[Temp_2];
Temp_2++;
Temp--;
}
Temp1[Temp_2]='\0';
Temp1[Temp_2+1]='\0';
lstrcat(Temp1,FileData.cFileName);
printf("File read is %S\n",Temp1);
}
if(!FindNextFile(hSearch, &FileData))
{
if(GetLastError() == ERROR_NO_MORE_FILES)
{
if(Completed == Count)
{
printf("Exiting....\n");
break;
}
lstrcpy(DirPath, Paths[Completed]);
lstrcat(DirPath,"*\0.\0*\0\0\0");
Completed++;
hSearch = FindFirstFile(DirPath, &FileData);
if(!hSearch)
RetValue =0;
continue;
}
else
{
printf("Could not find next file.\n");
break;
}
}
}
FindClose(hSearch);
}
In Win32, in every directories, two hidden files will be there ('.' and '. .'). Hence two FindNextFile statements are removed here.
No comments:
Post a Comment