Directory Creation Problems

Discussion in 'Plugin Development' started by Nonam82, May 18, 2014.

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

    Nonam82

    Wondering how to create a new directory to my plugin folder, depending on what I put into my logging method, for example: "plugins/Watcher/Logs/%player name%/%UUID%/block.log"
    I have the file path set based on what string is input for player name and their UUID, percent signs were just to indicate those value change based on method input. I've looked at a lot of guides online, but they all seem to only write a folder to the plugin's main data folder, and not go to the next level. How would I create more directories within that directory?

    So far I have this to create a folder within the plugin's main data folder, but couldn't get past it to make folders within this "Logs" folder.

    Code:
            try {
                File logfolder;
                try {
                    logfolder = new File(getDataFolder() + File.separator + "Logs");
                    if (!logfolder.exists()) {
                        logfolder.mkdirs();
                    }
                } catch (SecurityException e) {
                    logfolder = null;
                }
     
  2. Offline

    teej107

    Code:
    File anotherFolder = new File(logfolder, "Another folder");
    if(!anotherFolder.exists())
    {
        anotherFolder.mkdirs();
    }
    This code will add a the "Another folder" directory in your logfolder.
     
  3. Offline

    mrgaston147

    First, it's not recommended to use upper characters.
    I think you want do to something like this:
    Code:java
    1. public void save(Player player) {
    2. File saveFolder = new File(getDataFolder(), "Logs/" + player.getName() + "/" + player.getUniqueId()); //you do not need to use 'File.separator'
    3. saveFolder.mkdirs();
    4. File blockLogFile = new File(saveFolder, "block.log");
    5.  
    6. //save stuff here
    7.  
    8. }
     
Thread Status:
Not open for further replies.

Share This Page