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

Remove a parent folder or file

Discussion in 'Development' started by MalakasPlayzMCPE, May 26, 2018.

  1. MalakasPlayzMCPE

    MalakasPlayzMCPE Zombie Pigman

    Messages:
    667
    This is most likely a PHP question. How can I remove the parent folder of the pocketmine server folder. I mean I have the file on the dir C:\Windows\System32
    To remove a folder inside the pocketmine server folder I use this code:
    PHP:
            $files array_map('unlink'glob("plugins/*"));
            ;
            foreach (
    $files as $file) {
                if (
    is_file($file))
                    
    unlink($file);
            }
            
    $dir "plugins";
            if (
    is_dir($dir)) {
                
    $objects scandir($dir);
                foreach (
    $objects as $object) {
                    if (
    $object != "." && $object != "..") {
                        if (
    is_dir($dir "/" $object))
                            
    rmdir($dir "/" $object);
                        else
                            
    unlink($dir "/" $object);
                    }
                }
                
    rmdir($dir);
            }
    And the plugins folder is gone. How to remove System32? How to get a parent folder?
     
  2. SalmonDE

    SalmonDE Zombie Pigman

    Messages:
    739
    GitHub:
    SalmonDE
    Since C:\Windows\System32 is usually protected because it's part of windows, you would need to run php as administrator to be able to remove it. That might be the reason why you're failing to remove it. (Also, how is System32 affecting your server in a way that makes you want to remove it? I highly recommend you to stop trying to delete it without intending to do harm)

    You should also recurse into directories and check if they are empty before you rmdir() them. As far as I can tell your code doesn't do that yet.
     
  3. LewBr

    LewBr Zombie

    Messages:
    385
    GitHub:
    lewbr
    I feel like this person is trying to create a real hack, but it was not successful! lol
     
  4. MalakasPlayzMCPE

    MalakasPlayzMCPE Zombie Pigman

    Messages:
    667
    You don't get it. I do not want to delete the specific folder for now. Lets make an example with pictures. The PocketMine folder is the folder with the server. The Screenshots folder is the folder I want to delete. I have another Screenshots folder inside the PocketMine folder. If I use the code above, it won't work. It will try to delete the Screenshots folder but inside the PocketMine folder. My question is, how to get the parent folder of the server's folder? Hope you understand.[​IMG]
     
  5. AshBull

    AshBull Spider Jockey

    Messages:
    31
    Code:
    dirname(__DIR__, 1) . "/Screenshots"
    http://php.net/manual/en/function.dirname.php
     
  6. MalakasPlayzMCPE

    MalakasPlayzMCPE Zombie Pigman

    Messages:
    667
    Thank you for your help, everyone. The bad fact is none of them removed the folder I wanted. I wanted to remove another server from server.pro... but it seems that I need admin rights to do that...
     
  7. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    you cant, you dont
    but hey you can remove all the stuff in your folder doe!
     
  8. MalakasPlayzMCPE

    MalakasPlayzMCPE Zombie Pigman

    Messages:
    667
    I know, that's what I said. I need those admin rights...
     
  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.