warcsum/warcsum.c
/* Process all warc.gz files in a directory */
Process all warc.gz files in a directory
Process all warc . gz files in a directory
int
process_directory (char* input_dir, FILE* f_out, z_stream* z, struct warcsum_struct* ws)
{
  DIR *dir;
  struct dirent *ent;
  struct stat file_stat;
  if ((dir = opendir (input_dir)) != NULL)
    {
      while ((ent = readdir (dir)) != NULL)
        {
          char full_file_path[FILE_NAME_LENGTH];
          strcpy (full_file_path, input_dir);
          strcat (full_file_path, "/");
          strcat (full_file_path, ent->d_name);
          if (stat (full_file_path, &file_stat))
            {
              perror ("Error processing file: ");
            }
          if (!strcmp_case_insensitive (ent->d_name, ".")
              || !strcmp_case_insensitive (ent->d_name, ".."));
          else if (S_ISREG (file_stat.st_mode))
            {
              process_file (full_file_path, f_out, z, ws);
            }
          else if (S_ISDIR (file_stat.st_mode))
            {
              process_directory (full_file_path, f_out, z, ws);
            }
          else
            {
              if (ws->args.verbose == 2)
                {
                  fprintf (stderr, "%s is neither a regular file nor a directory!\n",
                           ent->d_name);
                }
            }
        }
      closedir (dir);
      return 0;
    }
  perror ("Could not open directory !!\n");
  return 1;
}
int process_directory ( char * input_dir , FILE * f_out , z_stream * z , struct warcsum_struct * ws ) { DIR * dir ; struct dirent * ent ; struct stat file_stat ; if ( ( dir = opendir ( input_dir ) ) != NULL ) { while ( ( ent = readdir ( dir ) ) != NULL ) { char full_file_path [ FILE_NAME_LENGTH ] ; strcpy ( full_file_path , input_dir ) ; strcat ( full_file_path , " " ) ; strcat ( full_file_path , ent -> d_name ) ; if ( stat ( full_file_path , & file_stat ) ) { perror ( " " ) ; } if ( ! strcmp_case_insensitive ( ent -> d_name , " " ) || ! strcmp_case_insensitive ( ent -> d_name , " " ) ) ; else if ( S_ISREG ( file_stat . st_mode ) ) { process_file ( full_file_path , f_out , z , ws ) ; } else if ( S_ISDIR ( file_stat . st_mode ) ) { process_directory ( full_file_path , f_out , z , ws ) ; } else { if ( ws -> args . verbose == 2 ) { fprintf ( stderr , " \n " , ent -> d_name ) ; } } } closedir ( dir ) ; return 0 ; } perror ( " \n " ) ; return 1 ; }
Process all warc.gz files in a directory
Process all warc . gz files in a directory
// cat dir path to file // if "." or "..", skip it // if a regular file, process it // if a directory, recurse through it // add '/' to the end of the directory path