[LibGDX] Getting list of folders in directory?

EDIT: It correctly finds files, just not folders.

I’m trying for the first time to parse files. I have a folder called “file” and inside that a folder called “Test folder”. I want to be able to write the Test folder’s name (Which is ‘Test Folder’) in the middle of the screen. However, when I do that I get an array index out of bounds exception which I suppose means it’s not finding a folder inside the “file” folder.

What I have:


public class MenuScreen implements Screen {
	
	Core core;
	public OrthographicCamera cam;
	public StretchViewport stretchViewport;
	public FileHandle[] fileList;
	
	private BitmapFont font;
	private SpriteBatch spriteBatch;
	
	public MenuScreen(Core core){
		this.core = core;
	}

	@Override
	public void show() {
		cam = new OrthographicCamera(480, 640);
		stretchViewport = new StretchViewport(480, 640, cam);
		stretchViewport.apply();
		
		font = new BitmapFont();
		spriteBatch = new SpriteBatch();
		// Initalize folder list
		fileList = Gdx.files.local("file/").list();
		
	}

	@Override
	public void render(float delta) {
		Gdx.gl.glClearColor(243f/255f,163f/255f,109f/255f, 1);
		Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
		cam.update();
		
		spriteBatch.begin();
		font.draw(spriteBatch, fileList[0].toString(), 480/2, 640/2);
		spriteBatch.end();
		
	}

	@Override
	public void resize(int width, int height) {
		stretchViewport.setWorldSize(width, height);	
		
	}

Use list() with the FileFilter parameter and just do this:

fileHandle.list(new FileFilter() {
      public boolean accept(File file) {
            return true;
      }
});

still getting Array Index out of bounds exception.

Well if that is all of your code then fileList is blank, which can narrow your problem down to the only way a blank list should be the expected output.

// from FileHandle.java
File file = file();
String[] relativePaths = file.list();
if (relativePaths == null) return new FileHandle[0];

And in java.io.File’s list() function, this is where relativePaths is null.

[quote]Returns null if this abstract pathname does not denote a directory, or if an I/O error occurs.
[/quote]
Check your path name, that is where your error seems to lie.