How to display file copy progress in 10.8

后端 未结 4 1221
心在旅途
心在旅途 2021-01-07 11:58

FSCopyObjectAsync is Deprecated in OS X v10.8, Now how to display progress indictor for file copy operation.

4条回答
  •  一整个雨季
    2021-01-07 12:15

    Coping files with progressIndicator in C

    #define BUFSIZE (64*1024)
    
    void *thread_proc(void *arg);
          {
              //outPath & inPatn an NSString paths
    
              char buffer[BUFSIZE];
              const char * outputFile = [outPath UTF8String];
              const char * inputFile = [inPath UTF8String];
              int in = open(inputFile, O_RDONLY);
              int out = open(outputFile, O_WRONLY | O_CREAT | O_TRUNC);
    
              vvolatile off_t progress;
              progress = 0;             
              ssize_t bytes_read;
              double fileSize = 0;
              NSNumber * theSize;
    
              if ([inPath getResourceValue:&theSize forKey:NSURLFileSizeKey error:nil])
                      fileSize = [theSize doubleValue];
    
              [progressIndicator setMaxValue:fileSize];      
              while((bytes_read = read(in, buffer, BUFSIZE)) > 0)
              {
                  write(out, buffer, BUFSIZE);
                  progress += bytes_read;
    
                  [progressIndicator setDoubleValue:progress];
    
              }
              // copy is done, or an error occurred
              close(in);
              close(out);
          }
    

提交回复
热议问题