遍历目录得到文件

// flash.cpp : Defines the entry point for the console application.
//

#include "windows.h"
#include "stdio.h"
#include "string.h"

char dir[260];

void GetFile( char* FilePath )
{
 char temp[260],temp1[260];
    strcpy( temp ,FilePath );
    WIN32_FIND_DATA FindFileData;
    HANDLE hFind;
    strcat( temp , "*");
    //printf("%s",temp);
    hFind = FindFirstFile( temp , &FindFileData );
    //printf("%s/n",FindFileData.cFileName );
 if ( hFind == INVALID_HANDLE_VALUE ){
              //printf ("Invalid File Handle. GetLastError reports %d/n", GetLastError ());
              //exit(0);
    }
    else{   
  //printf("%s",temp1);          
        do{
   strcpy( temp1 , FilePath );
            strcat( temp1 , FindFileData.cFileName );
            if(strcmp( FindFileData.cFileName , "." )!=0&&strcmp( FindFileData.cFileName , ".." )!=0){
             if( FindFileData.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY ){
     strcat( temp1 , "//" );
                 GetFile( temp1 );
    }else{
                printf("%s/n",temp1 );
                /* do something here*/
             }                 
   }
        }while( FindNextFile( hFind,&FindFileData ) );

   }
   FindClose(hFind);
}

int main(int argc, char* argv[])
{
 if (argc!=2) printf("Grammar should be like this: flash [direction]./n");
 else {
  if (argv[1][strlen(argv[1])-1]!='//') {
   strcat(argv[1],"//");
  }
  GetFile(argv[1]);
 }
    return 0;
}

 

 

你可能感兴趣的:(遍历目录得到文件)