Calculation of file size and calculation of folder size

Source: Internet
Author: User

1 read the size of the folder in the local documents file (we can use the Nsdirectoryenumerator class)

NSString * Docupath = Nssearchpathfordirectoriesindomains(nsdocumentdirectory, Nsuserdomainmask, YES) [0];

not normally. Files are placed directly under the Documents folder to create a new folder

NSString * FilePath = [Docupath stringbyappendingpathcomponent:@ "DownLoadFile"];

Nsdirectoryenumerator * enumerator = [[Nsfilemanager Defaultmanager] enumeratoratpath: FilePath];

A long long size = 0;

While ([enumerator nextobject])

{

nsdictionary * dic = [enumerator fileattributes];

Size + = [dic fileSize];

}

2. Get the properties of a folder using

[[Nsfilemanager Defaultmanager] attributesofitematpath:[filepath] error:nil];

It can only query the folder's properties to not calculate the size of the folder

3. Calculate the size of the file download

Nsdictionary * info = [[Nsfilemanager Defaultmanager] attributesofitematpath:p ath error:Nil ];

long long size = [info fileSize];

4. Delete local ask and delete from cell

Pub_file * p = self . Receivearry[indexpath. Row];

Delete from local

[[Nsfilemanager Defaultmanager] removeitematpath: [filedownload creatpath:p. Name] Error:nil];

Remove from Table

[self. Receivearry removeobjectatindex: Indexpath.row];

[_tableview deleterowsatindexpaths:@[indexpath] withrowanimation: Uitableviewrowanimationautomatic];

Remove the file from the local technology directly by using the File Manager directly delete,,,,,,,, Delete the contents of the cell must first delete the contents of the source array, and then delete the corresponding cell of this content, or it will cause the program to crash

Calculation of file size and calculation of folder size

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.