//.h file
unsigned long long int fileSize;
// .m file
NSString *folderPath = @"/Users/Desktop/myFolder";
[self folderSize:folderPath];
- (unsigned long long int)folderSize:(NSString *)folderPath {
NSArray *filesArray = [[NSFileManager defaultManager] subpathsOfDirectoryAtPath:folderPath error:nil];
NSEnumerator *filesEnumerator = [filesArray objectEnumerator];
NSString *fileNames;
//unsigned long long int fileSize = 0;
fileSize = 0;
while (fileNames = [filesEnumerator nextObject]) {
NSDictionary *fileDictionary = [[NSFileManager defaultManager] attributesOfItemAtPath:[folderPath stringByAppendingPathComponent:fileNames] error:nil];
fileSize += [fileDictionary fileSize];
}
NSLog(@"filesize==%llu",fileSize);
[self checkTotalSize];
return fileSize;
}
-(void)checkTotalSize {
fileSize = fileSize ;// + totalLength; // totallength is current file size
NSLog(@"totsize==%llu",fileSize);
if (fileSize >= 1000000000) {
[self.urlConnection cancel];
receivedData = nil;
}
}
unsigned long long int fileSize;
- (unsigned long long int)folderSize:(NSString *)folderPath;
-(void)checkTotalSize;// .m file
NSString *folderPath = @"/Users/Desktop/myFolder";
[self folderSize:folderPath];
- (unsigned long long int)folderSize:(NSString *)folderPath {
NSArray *filesArray = [[NSFileManager defaultManager] subpathsOfDirectoryAtPath:folderPath error:nil];
NSEnumerator *filesEnumerator = [filesArray objectEnumerator];
NSString *fileNames;
//unsigned long long int fileSize = 0;
fileSize = 0;
while (fileNames = [filesEnumerator nextObject]) {
NSDictionary *fileDictionary = [[NSFileManager defaultManager] attributesOfItemAtPath:[folderPath stringByAppendingPathComponent:fileNames] error:nil];
fileSize += [fileDictionary fileSize];
}
NSLog(@"filesize==%llu",fileSize);
[self checkTotalSize];
return fileSize;
}
-(void)checkTotalSize {
fileSize = fileSize ;// + totalLength; // totallength is current file size
NSLog(@"totsize==%llu",fileSize);
if (fileSize >= 1000000000) {
[self.urlConnection cancel];
receivedData = nil;
}
}
No comments:
Post a Comment