Solved yml files

Discussion in 'Spigot Plugin Development' started by MadMaxCookie, May 22, 2016.

  1. Hello so I've had a folder and yml files on it such as warpnames.yml


    filename is a name of warp

    I'm wondering how do I get all names of files at the warps folder without getting the .yml thingyy.
    help please.
  2. This may help

    Create a File object, passing the directory path to the constructor. Then use the listFiles() to retrieve an array of File objects for each file in the directory, and then call the getName() method to get the filename.

    Code (Text):
    File[] files = new File("/path/to/the/directory").listFiles(new FilenameFilter() { @Override public boolean accept(File dir, String name) { return name.endsWith(".xml"); } });
  3. then I have to change this one at the same way right ?
    Code (Java):
    return name.endsWith(".xml");
    • Agree Agree x 1
  4. Better way would be to save the names of the warps and then load the files via:
    Code (Text):
    FileConfiguration config = YamlConfiguration.loadConfiguration(new File("plugins/PluginName/fileName.yml"));
    • Informative Informative x 1
  5. oh well you don't get what I'm saying but @Pr0Pancakeslol makes sense.

    Read what I want.
    • Like Like x 1
  6. If I correctly understand that the Warps folder contains all warps, and every warp has its own .yml file, this is what you need.
    Code (Text):

            for(File file : new File(plugin.getDataFolder().getAbsolutePath() + "/Warps/").listFiles()){
                    String warpName = file.getName().substring(0, file.getName().length() - 4); // remove .yml
    • Informative Informative x 2
  7. Thanks for your help aswell I can clearly understand what I wanted to do but this code simply contradicts with thanks for your help anyway

    have to take a look with the prefix before messaging :D
    • Like Like x 1