1.15.2 how to get all files in "getResouce();"

Discussion in 'Spigot Plugin Development' started by Kolia1_1, Jan 27, 2020.

Thread Status:
Not open for further replies.
  1. upload_2020-1-27_14-54-24.png


    How do I get all the files in the plugin resources and save.
    I know that you can get them using saveResource("file") , but if there will be many files, I need a method that will take all the files.
     
  2. I'm not sure if there is a method for that, but you can use a for loop.
     
  3. Learn using stackoverflow and searching
    Code (Java):

    CodeSource src = MyClass.class.getProtectionDomain().getCodeSource();
    if (src != null) {
      URL jar = src.getLocation();
      ZipInputStream zip = new ZipInputStream(jar.openStream());
      while(true) {
       ZipEntry e = zip.getNextEntry();
       if (e == null)
         break;
       String name = e.getName();
       if (name.startsWith("path/to/your/dir/")) {
         /* Do something with this entry. */
         ...
       }
      }
    }
     
    You can try with this
     
    • Like Like x 1
  4. Thank you!
     
Thread Status:
Not open for further replies.