Deleting Temp-Folder

Hi,

I am converting a PPT to images in order to show an Instruction prior to the simulation I built in jMonkey. I store the images in a tmp folder inside my assets-folder. Now I have two questions:
• When deleting the temp-folder (FileUtils.deleteDirectory()) after changing the simulation task while the game is running, I get an error message:
[java]java.lang.IllegalArgumentException: Given root path “/Users/XXX/tmp” is not a directory
at com.jme3.asset.plugins.FileLocator.setRootPath(FileLocator.java:53)[/java]
This appears when loading any other asset even if they have nothing to do with the tmp/ folder
Do I somehow need to remove the folder from the assetManager as well?

• is there any way to make use of the systems temp Folder (File.createTempFile())? The way I understood it, there is no easy way of accessing files outside the assets/ folder?

Which FileUtils do you refer to?
Why not create the temp folder inside the user’s home directory with the common File class?

I refer to : org.apache.commons.io.FileUtils

I would actually much prefer to create the folder in the users Home directory, and maybe I am overseeing the way to do it, but I could not figure out how to load assets (Images for NiftyGUI) from folders outside the assets-Folder up to now. Is there a way?

Thanks for your reply!!

Yes, you can add the temp folder to the assetManager in this way
assetManager.registerLocator(PATH,FileLocator.class);

I usually store applications data in the Home directory on linux and in the %APPDATA% on Windows. You can get those directory with this code
[java]
public static String getHomeDirectory(){
return (System.getProperty(“os.name”).toUpperCase().contains(“WIN”)?System.getenv(“APPDATA”):System.getProperty(“user.home”))+File.separator;
}
[/java]

You can create a new directory with File.mkdirs(); and delete it with File.delete();, but it must be empty, so you should remove its content before.
[java]
public static void delete(File fl) {
if (fl.isDirectory() && fl.list().length != 0) {
for (File file : fl.listFiles())
delete(file);
delete(fl);
} else {
fl.delete();
}
}[/java]

1 Like

Hey, thanks a lot!!

that very “basic” knowledge (I should probably have gotten from the tutorials:)) about how to access folders outside the assets folder helped me a lot! No need to create an extra temp-Folder now …