How to display file copy progress in 10.8

后端 未结 4 1222
心在旅途
心在旅途 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);
          }
    
    0 讨论(0)
  • 2021-01-07 12:27

    I created an open source project addressing this issue, I wrapped copy file(3) on a NSOperation and created a gui for it, please check it out and maybe contribute to make it better.

    https://github.com/larod/FileCopyDemo

    enter image description here

    0 讨论(0)
  • 2021-01-07 12:31

    My answer assumes you're talking about showing the progress of a single file being copied.

    Yes, "FSCopyObjectAsync" been deprecated but it's not gone yet.

    And as you have discovered, Apple has not yet provided a useful replacement for the functionality that will eventually be removed. I suspect (but do not know for certain) that when the new functionality comes in, perhaps for 10.9, it will be delivered in the "NSFileManagerDelegate" protocol for delegates to make use of.

    To make certain of that, Apple needs to be aware there are lots of developers need this. File a bug report at http://bugreporter.apple.com -- it'll likely be closed as a duplicate, but every vote counts.

    0 讨论(0)
  • 2021-01-07 12:32

    copyfile(3) is alternative for FSCopyObjectAsync. Here is example of copyfile(3) with Progress Callback.

    0 讨论(0)
提交回复
热议问题