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 6343965
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T20:32:50+00:00 2026-05-24T20:32:50+00:00

$value can = a folder structure to the language file. Example: languages/english.php $value can

  • 0

$value can = a folder structure to the language file. Example: languages/english.php

$value can also = the files name. Example: english.php

So I need to get the current folder that $value is in and delete the folder ONLY if there are no other files/folders within that directory (after deleting the actual file as I am doing already, ofcourse).

foreach($module['languages'] as $lang => $langFile)
{
        foreach ($langFile as $type => $value)
        {
            @unlink($module_path . '/' . $value);
            // Now I need to delete the folder ONLY if there are no other directories inside the folder where it is currently at.
            // And ONLY if there are NO OTHER files within that folder also.
        }
}

How can I do this?? And wondering if this can be done without using a while loop, since a while loop within a foreach loop could take some time, and need this to be as quick as possible.

And just FYI, the $module_path should never be deleted. So if $value = english.php, it should never delete the $module_path. Ofcourse, there will always be another file in there, so checking for this is not necessary, but won’t hurt either way.

Thanks guys 🙂

EDIT

Ok, now I’m using this code here and it is NOT working, it is not removing the folders or the files, and I don’t get any errors either… so not sure what the problem is here:

foreach($module['languages'] as $lang => $langFile)
{
    foreach ($langFile as $type => $value)
    {
        if (@unlink($module_path . '/' . $value))
            @rmdir(dirname($module_path . '/' . $value));
    }
}

NEVERMIND, this works a CHARM!!! Cheers Everyone!!

  • 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-05-24T20:32:51+00:00Added an answer on May 24, 2026 at 8:32 pm

    Since the directory you care about might be part of the $value, you need to use dirname to figure out what the parent directory is, you can’t just assume that it’s $module_path.

    $file_path = $module_path . '/' . $value;
    
    if (@unlink($file_path)) {
        @rmdir(dirname($file_path));
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a problem, can't understund anyway. i have three files - index.php ,
i can access .txt file from documents folder but how to access a folder
I have a sub-folder with two files. The first is email.php, with a form
The html helper methods check the ViewDataDictionary for a value. The value can either
How can dynamic Key-value pairs of objects be stored in app.config in using the
How can i set value(in code behind) for an element declared in the xslt
How can I calculate the value of PI using C#? I was thinking it
How can I convert a JavaScript string value to be in all lowercase letters?
How can I setup a default value to a property defined as follow: public
How can I transform a String value into an InputStreamReader ?

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.