Guy*_*lon 2 iphone objective-c nsfilemanager ios progress-bar
我复制文件然后我的应用程序完成从资源启动到缓存目录.但我想在复制文件时更新我的进度条.
我使用以下代码复制文件:
-(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;
}
Run Code Online (Sandbox Code Playgroud)
我想不出一个好主意,如何更新进度条根据复制文件的进度.
在高级别,您可以接近以下内容:
current_size.current_size / total_size然后你只想找出一个文件的大小,你实际上不需要打开它.就像这样使用NSFileManager:
NSDictionary *attributes = [[NSFileManager defaultManager] attributesOfItemAtPath:self.finalPath error:NULL];
unsigned long long fileSize = [attributes fileSize]; // in bytes
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2210 次 |
| 最近记录: |