File Memory size calculation, memory size Calculation

Source: Internet
Author: User

File Memory size calculation, memory size Calculation

/**

* Calculate the size of all files in a file.

Note: to calculate the size of all files in a folder, you must first obtain all files, then obtain the size of all files, and then add them together.

*/

NSFileManager * manager = [NSFileManager defamanager manager];

// Extract the file that requires Calculation

NSArray * arr = [manager subpathsAtPath: @ "/Users/zhangyunjiang/Desktop"];

NSMutableString * strM = [NSMutableString string];

NSMutableString * strM1 = [NSMutableString string];

For (int I = 0; I <arr. count; I ++ ){

// Add all file names to the string

[StrM appendFormat: @ "// Users/zhangyunjiang/Desktop/% @", arr [I];

}

// Convert the string with the added file name into an array

NSArray * arr1 = [strM componentsSeparatedByString: @ "//"];

For (int j = 0; j <arr. count; j ++ ){

// Extract the attribute content of each file name from the array

NSDictionary * dic = [manager attributesOfItemAtPath :( arr1 [j]) error: nil];

// Find the memory size occupied by files in the content

NSString * str3 = dic [NSFileSize];

[StrM1 appendFormat: @ "-% @", str3];

}

// Calculate

NSArray * arr2 = [strM1 componentsSeparatedByString: @ "-"];

Double sum = 0;

For (int I = 0; I <arr2.count; I ++ ){

NSString * str3 = [arr2 objectAtIndex: I];

If (str3 = nil ){

}

Else

{

Sum + = [str3 intValue];

}

}

// Convert the space into a GM

Double newsum = sum/1024/1024/1024;

NSLog (@ "% f", sum );

NSLog (@ "% f", newsum );

}

Return 0;

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.