Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7943777
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T00:22:18+00:00 2026-06-04T00:22:18+00:00

I have plenty of empty temporary folders in app’s Document folder. How to delete

  • 0

I have plenty of empty temporary folders in app’s Document folder.

How to delete them all?

I tried:

NSArray *folders = [[NSFileManager defaultManager]contentsOfDirectoryAtURL:[self applicationDocumentsDirectory] includingPropertiesForKeys:[NSArray arrayWithObject:@"NSURLIsDirectoryKey"] options:0 error:nil];
if (folders) {
    for (NSURL *url in folders) {
        [[NSFileManager defaultManager]removeItemAtURL:url error:nil];
    }
}

but it deletes all, not only folders

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T00:22:19+00:00Added an answer on June 4, 2026 at 12:22 am

    This snippet of code deletes only directiories that are empty.

    NSFileManager *fileManager = [[NSFileManager alloc] init];
    NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
    
    NSArray *files = [fileManager contentsOfDirectoryAtPath:documentsDirectory error:nil];
    for (NSString *file in files) {
        NSString *fullPath = [documentsDirectory stringByAppendingPathComponent:file];
        NSError *error;
        if ([[fileManager contentsOfDirectoryAtPath:fullPath error:&error] count]==0) {
            // check if number of files == 0 ==> empty directory
            if (!error) { 
                // check if error set (fullPath is not a directory and we should leave it alone)
                [fileManager removeItemAtPath:fullPath error:nil];
            }
        }
    }
    

    If you simply want to delete all directories (both empty and not empty) the snippet can be simplified into this:

    NSFileManager *fileManager = [[NSFileManager alloc] init];
    NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
    
    NSArray *files = [fileManager contentsOfDirectoryAtPath:documentsDirectory error:nil];
    for (NSString *file in files) {
        NSString *fullPath = [documentsDirectory stringByAppendingPathComponent:file];
        if ([fileManager contentsOfDirectoryAtPath:fullPath error:nil])
            [fileManager removeItemAtPath:fullPath error:nil];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a CListCtrl with plenty of room for all of the items, and
I am developing web app using asp.net. I have plenty of javascript files which
Ok, I see plenty of these errors around. I have tried everything I know
I have a plenty of tables and databases. most of the tables have empty
I have plenty of experience with this in PHP, but am fairly new to
For IE 6 we have plenty of bugs to bug us as a designer.
I have got the following class structure, and have plenty of classes like C
I have read plenty of C# examples of Value Objects, and I understand that
I have seen plenty of discussion regarding the fastest way to select a first
In our project, we have a plenty of unit tests. They help to keep

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.