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

  • Home
  • SEARCH
  • 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 8936699
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T10:16:19+00:00 2026-06-15T10:16:19+00:00

If an item no longer exists in an array but there is a folder

  • 0

If an item no longer exists in an array but there is a folder with the no longer required name. What would be the best way to check and remove the folder?

Example:

I have an array('blah','apple','oneDirection'); I will then run a command to create a folder/dir in a specific location with the names in the array but if oneDirection is no longer in the array I would like to delete the folder/dir -> Would I use in_array?

The array data comes from an external JSON feed so it will be removed automatically and when this is done I would like it to delete the folder/dir – I am not sure on the array and folder/dir name checking structure

  • 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-15T10:16:20+00:00Added an answer on June 15, 2026 at 10:16 am

    Just a quick snippet that might serve as an example.

    function del_dir($dir, $key, $root) {
            // may need to do more here like delete recursively
            $rp= realpath($root .'\\'. $dir);
            rmdir( $rp);
            echo "folder: $rp : removed\n";
    }
    
    // your root folder
    $home_dir= "c:\\tmp";
    // your array of folders
    $folders= array("folder1", "folder2");
    $fs_folders=array();
    if ($dh = opendir($home_dir)) {
        while (($f = readdir($dh)) !== false) {
            if(is_dir("$home_dir\\$f")){
                if ($f != "." && $f != "..")
                    $fs_folders[]= $f;
            }
        }
        closedir($dh);
    }
    
    $todel= array_diff($fs_folders, $folders);
    array_walk($todel, "del_dir", $home_dir);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

class item(models.Model): name = models.CharField() class itemTxns(models.Model): item = models.ForeignKey(item) txnDate = models.DateField() txn
I have an Item class. There's an itemType field inside of that class which
Currently the list item # appears on the right. If you remove the float
I have product item webpages located in /product/items/*.html?id=12345&ref=54321 and I would like the webpages
I have an item table where there is a type column. The values here
if($(xml).find(error) == 'Search short, please enter a longer search item') { showMinChar(); } And
I have got a menu list: <ul> <li class=marked>First item</li> <li>Second much longer than
First I apologize for a somewhat longer sample code and question... There are three
I had my code work fine yesterday, but today I can no longer get
I had the following in the <head> of a GSP <script type=text/javascript> $(button.remove-item).click(function() {

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.