I copy files then my application is finish launching from resource to caches directory. but I want to update my progress bar during copying the files.
I copy the file with the code below:
-(BOOL)copyDirectory:(NSString*)source toDirectory:(NSString*)targat
{
BOOL retVal = YES;
NSFileManager *fileManager = [[NSFileManager alloc] init];
NSError *error;
if ([fileManager fileExistsAtPath:targat] == YES)
{
NSError *error = nil;
[fileManager removeItemAtPath:targat error:&error];
}
if(![fileManager copyItemAtPath:source
toPath:targat
error:&error])
{
NSLog(@"Error copy files: %@", [error description]);
retVal = NO;
}
[fileManager release];
return retVal;
}
I can not think about a good idea, how to update the progress bar According to the progress of copying files.
In high level you may approach the following :
current_size. current_size / total_sizeThen you just want to find out the size of a file, you don't actually have to open it. Just use NSFileManager like this:
NSDictionary *attributes = [[NSFileManager defaultManager] attributesOfItemAtPath:self.finalPath error:NULL];
unsigned long long fileSize = [attributes fileSize]; // in bytes
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With