1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

Deleting file path directory.

Discussion in 'Development' started by MC ATECH, Jul 13, 2017.

  1. MC ATECH

    MC ATECH Baby Zombie

    Messages:
    117
    GitHub:
    mcpeatech
    Hello in a recent plugin that I am developing I have come across an error in the console:
    PHP:
    Warningunlink(C:\Users\test\Desktop\new\/worlds/TnTg1\region\r.-1.-1.mca): Permission denied in C:\Users\test\Desktop\new\plugins\pvp\src\pvp\Main.php on line 301

    Warning
    unlink(C:\Users\test\Desktop\new\/worlds/TnTg1\region\r.-1.0.mca): Permission denied in C:\Users\test\Desktop\new\plugins\new\src\new\Main.php on line 301

    Warning
    unlink(C:\Users\test\Desktop\new\/worlds/TnTg1\region\r.0.-1.mca): Permission denied in C:\Users\test\Desktop\new\plugins\pvp\src\pvp\Main.php on line 301

    Warning
    unlink(C:\Users\test\Desktop\new\/worlds/TnTg1\region\r.0.0.mca): Permission denied in C:\Users\test\Desktop\new\plugins\pvp\src\pvp\Main.php on line 301

    Warning
    rmdir(C:\Users\test\Desktop\new\/worlds/TnTg1\region): Directory not empty in C:\Users\test\Desktop\new\plugins\pvp\src\pvp\Main.php on line 306

    Warning
    rmdir(C:\Users\test\Desktop\new\/worlds/TnTg1): Directory not empty in C:\Users\test\Desktop\new\plugins\pvp\src\pvp\Main.php on line 306
    In my understanding I believe this happens due to the server software dealing with a different world format. But I am not so sure.
    The code to delete the directory is as follows, can anyone see where im going wrong?

    PHP:
    public function deleteDirectory($dirPath) {
            if (
    is_dir($dirPath)) {
                
    $objects scandir($dirPath);
                foreach (
    $objects as $object) {
                    if (
    $object != "." && $object != "..") {
                        if (
    filetype($dirPath DIRECTORY_SEPARATOR $object) == "dir") {
                            
    $this->deleteDirectory($dirPath DIRECTORY_SEPARATOR $object);
                        } else {
                            
    unlink($dirPath DIRECTORY_SEPARATOR $object);
                        }
                    }
                }
                
    reset($objects);
                
    rmdir($dirPath);
            }
        }
    Thanks, MC ATECH
     
  2. robske_110 (Tim)

    robske_110 (Tim) Wither Skeleton Poggit Reviewer

    Messages:
    1,342
    GitHub:
    robske110
    nope, the php process just doesn't have enough rights to delete the file, hence "Permission denied"
    Check file permissions.
     
  3. MC ATECH

    MC ATECH Baby Zombie

    Messages:
    117
    GitHub:
    mcpeatech
    hmm cant seem to solve this.. The permission files are all still the same didn't change anything?
     
  4. HittmanA

    HittmanA Zombie

    Messages:
    207
    GitHub:
    hittmana
    Perhaps you could try
    PHP:
    exec("sudo rm FileOrDirectoryToDelete");
     
  5. robske_110 (Tim)

    robske_110 (Tim) Wither Skeleton Poggit Reviewer

    Messages:
    1,342
    GitHub:
    robske110
    He's obviously using windows, so that won't work.
     
  6. MC ATECH

    MC ATECH Baby Zombie

    Messages:
    117
    GitHub:
    mcpeatech
    So is there no way around this? If on windows?
     
  7. robske_110 (Tim)

    robske_110 (Tim) Wither Skeleton Poggit Reviewer

    Messages:
    1,342
    GitHub:
    robske110
    well, basically you need to check file permissions. As I do not have access to a windows pc currently (linux rules!) I can't provide you with screenshots, maybe someone else can or simply google "change permissions of folders recursively windows"
     
  8. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    How are you starting your server?
     
  9. MC ATECH

    MC ATECH Baby Zombie

    Messages:
    117
    GitHub:
    mcpeatech
    I use the windows command script (start) to start my server.
     
  10. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    So, it's started from a user with permission to edit the world files?
     
  11. MC ATECH

    MC ATECH Baby Zombie

    Messages:
    117
    GitHub:
    mcpeatech
    Well this script makes the server Console edit the world files?
     
  12. eDroid

    eDroid Witch

    Messages:
    59
    GitHub:
    edroiid
    This will work on windows:
    PHP:
    public function deleteDirectory($dirPath) {
        
    system("del /q ".$dirPath);
    }
     
    MC ATECH likes this.
  13. MC ATECH

    MC ATECH Baby Zombie

    Messages:
    117
    GitHub:
    mcpeatech
    Thank you!
    Will report back fĂȘter testing
     
  14. ProjectInfinity

    ProjectInfinity Witch

    Messages:
    58
    GitHub:
    projectinfinity
    Scary stuff, I wouldn't run anything using system that accepts input.

    You could try to disable UAC in Windows to see if it makes a difference. Personally whenever _anything_ happens on the C drive, my Windows 10 install gets very finicky about it.
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.