Get server root directory

Discussion in 'Spigot Plugin Development' started by DotRar, May 17, 2015.

Thread Status:
Not open for further replies.
  1. Hey, I have a folder named "backup" in my server directory, which I need to copy. How would I go about copying it? I currently have this:

    Code (Text):
    public void createWorld() throws IOException {
            File srcDir = new File("/backup");
            if (!srcDir.exists()) {
                Bukkit.getLogger().warning("Backup doesn not exist!");
                return;
            }
            File destDir = new File("/world");
            FileUtils.copyDirectory(srcDir, destDir);
            Bukkit.getServer().createWorld(new WorldCreator("world"));
    }
    When I run the server, I get this in the console:
    Code (Text):
    Backup doesn not exist!
    So, it's obviously having trouble getting the directory "backup".
     
  2. Got it! Requesting lock. For anyone else who needs it, here it is (I was testing it with my PC, replace the dir file with plugin.getDataFolder):
    Code (Text):
    public static void main(String[] args) {
            File dir = new File("C:"+File.pathSeparator+"Users"+File.pathSeparator+"RW"+File.pathSeparator+"Desktop");
            String str = dir.toString();
            String[] split = dir.toString().split(File.pathSeparator);
            String location = split[split.length - 3];
            System.out.println(location);
        }
     
    • Funny Funny x 1
    • Useful Useful x 1
Thread Status:
Not open for further replies.