Delete World Folder

Discussion in 'Plugin Development' started by Muod, May 1, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    Muod

    So I have this void I made,
    Code:
        public static void resetMap(){
            for(Chunk c : Bukkit.getWorld("Game").getLoadedChunks()) {
               
                c.unload(false, false);
               
                }
            final File path = Bukkit.getWorld("Game").getWorldFolder();
            if (Bukkit.unloadWorld("Game", true)) {
                System.out.println("Unloaded world");
                } else {
                System.err.println("Couldn't unload world");
                }
            if (path.exists()) {
                File files[] = path.listFiles();
                for (int i = 0; i < files.length; i++) {
                    if (files[i].isDirectory()) {
                        for(File f: files) {
                            if(f.isDirectory()) {
                                path.delete();
                            } else {
                                f.delete();
                            } 
                        }
                    } else {
                        files[i].delete();
                    }
                }
            }
        }
    Though when it is run from a command it only gets rid of
    level.dat
    level.dat_mcr
    level.dat_old
    session.lock
    and uid.dat
    Everything else is still there. I need the WHOLE folder to be deleted, anybody know how to do this?
     
  2. Muod
    Code:
    getWorldFolder().getParentFile().delete()
    This should delete the world folder
     
  3. Offline

    lrdemolition

    I dont think this is right?
    can someone confirm it
     
  4. Offline

    teej107

  5. Offline

    lrdemolition

    if (f.isDirectory()) {
    for (File c : f.listFiles())
    delete(c);

    teej107
     
  6. Offline

    teej107

    lrdemolition Close but you get the idea. Assuming delete(file) is your method, you also need to check if the file is a file or a directory. If it is a directory, use recursion (make sure you delete the folder too). If not, then just delete the file.
     
Thread Status:
Not open for further replies.

Share This Page