FileHandle dirHandle; if (Gdx.app.getType() == ApplicationType.Android) { dirHandle = Gdx.files.internal("some/directory"); } else { // ApplicationType.Desktop .. dirHandle = Gdx.files.internal("./bin/some/directory"); } for (FileHandle entry: dirHandle.list()) { // yadda ... }
public FileHandle[] list () { if (type == FileType.Internal) { try { String[] relativePaths = assets.list(file.getPath()); FileHandle[] handles = new FileHandle[relativePaths.length]; for (int i = 0, n = handles.length; i < n; i++) handles[i] = new AndroidFileHandle(assets, new File(file, relativePaths[i]), type); return handles; } catch (Exception ex) { throw new GdxRuntimeException("Error listing children: " + file + " (" + type + ")", ex); } } return super.list(); }
public FileHandle[] list () { if (type == FileType.Internal) { try { String[] relativePaths = assets.list(file.getPath()); FileHandle[] handles = new FileHandle[relativePaths.length]; for (int i = 0, n = handles.length; i < n; i++) handles[i] = new AndroidFileHandle(assets, new File(file, relativePaths[i]), type); return handles; } catch (Exception ex) { throw new GdxRuntimeException("Error listing children: " + file + " (" + type + ")", ex); } } return super.list(); }
private static final void traverse (FileHandle directory, String base, StringBuffer list) { if (directory.name().equals(".svn")) return; String dirName = directory.toString().replace("\\", "/").replace(base, "") + "/"; System.out.println(dirName); for (FileHandle file : directory.list()) { if (file.isDirectory()) { traverse(file, base, list); } else { String fileName = file.toString().replace("\\", "/").replace(base, ""); if (fileName.endsWith(".png") || fileName.endsWith(".jpg") || fileName.endsWith(".jpeg")) { list.append("i:" + fileName + "\n"); System.out.println(fileName); } else if (fileName.endsWith(".glsl") || fileName.endsWith(".fnt") || fileName.endsWith(".pack") || fileName.endsWith(".obj") || file.extension().equals("") || fileName.endsWith("txt")) { list.append("t:" + fileName + "\n"); System.out.println(fileName); } else { if (fileName.endsWith(".mp3") || fileName.endsWith(".ogg") || fileName.endsWith(".wav")) continue; list.append("b:" + fileName + "\n"); System.out.println(fileName); } } } } }
public FileHandle[] list (String suffix) { if (type == FileType.Internal) { try { String[] relativePaths = assets.list(file.getPath()); FileHandle[] handles = new FileHandle[relativePaths.length]; int count = 0; for (int i = 0, n = handles.length; i < n; i++) { String path = relativePaths[i]; if (!path.endsWith(suffix)) continue; handles[count] = new AndroidFileHandle(assets, new File(file, path), type); count++; } if (count < relativePaths.length) { FileHandle[] newHandles = new FileHandle[count]; System.arraycopy(handles, 0, newHandles, 0, count); handles = newHandles; } return handles; } catch (Exception ex) { throw new GdxRuntimeException("Error listing children: " + file + " (" + type + ")", ex); } } return super.list(suffix); }
public FileHandle[] list (String suffix) { if (type == FileType.Internal) { try { String[] relativePaths = assets.list(file.getPath()); FileHandle[] handles = new FileHandle[relativePaths.length]; int count = 0; for (int i = 0, n = handles.length; i < n; i++) { String path = relativePaths[i]; if (!path.endsWith(suffix)) continue; handles[count] = new AndroidFileHandle(assets, new File(file, path), type); count++; } if (count < relativePaths.length) { FileHandle[] newHandles = new FileHandle[count]; System.arraycopy(handles, 0, newHandles, 0, count); handles = newHandles; } return handles; } catch (Exception ex) { throw new GdxRuntimeException("Error listing children: " + file + " (" + type + ")", ex); } } return super.list(suffix); }
public FileHandle[] list (FilenameFilter filter) { if (type == FileType.Internal) { try { String[] relativePaths = assets.list(file.getPath()); FileHandle[] handles = new FileHandle[relativePaths.length]; int count = 0; for (int i = 0, n = handles.length; i < n; i++) { String path = relativePaths[i]; if (!filter.accept(file, path)) continue; handles[count] = new AndroidFileHandle(assets, new File(file, path), type); count++; } if (count < relativePaths.length) { FileHandle[] newHandles = new FileHandle[count]; System.arraycopy(handles, 0, newHandles, 0, count); handles = newHandles; } return handles; } catch (Exception ex) { throw new GdxRuntimeException("Error listing children: " + file + " (" + type + ")", ex); } } return super.list(filter); }
public FileHandle[] list (FilenameFilter filter) { if (type == FileType.Internal) { try { String[] relativePaths = assets.list(file.getPath()); FileHandle[] handles = new FileHandle[relativePaths.length]; int count = 0; for (int i = 0, n = handles.length; i < n; i++) { String path = relativePaths[i]; if (!filter.accept(file, path)) continue; handles[count] = new AndroidFileHandle(assets, new File(file, path), type); count++; } if (count < relativePaths.length) { FileHandle[] newHandles = new FileHandle[count]; System.arraycopy(handles, 0, newHandles, 0, count); handles = newHandles; } return handles; } catch (Exception ex) { throw new GdxRuntimeException("Error listing children: " + file + " (" + type + ")", ex); } } return super.list(filter); }
public FileHandle[] list (FileFilter filter) { if (type == FileType.Internal) { try { String[] relativePaths = assets.list(file.getPath()); FileHandle[] handles = new FileHandle[relativePaths.length]; int count = 0; for (int i = 0, n = handles.length; i < n; i++) { String path = relativePaths[i]; FileHandle child = new AndroidFileHandle(assets, new File(file, path), type); if (!filter.accept(child.file())) continue; handles[count] = child; count++; } if (count < relativePaths.length) { FileHandle[] newHandles = new FileHandle[count]; System.arraycopy(handles, 0, newHandles, 0, count); handles = newHandles; } return handles; } catch (Exception ex) { throw new GdxRuntimeException("Error listing children: " + file + " (" + type + ")", ex); } } return super.list(filter); }
public FileHandle[] list (FileFilter filter) { if (type == FileType.Internal) { try { String[] relativePaths = assets.list(file.getPath()); FileHandle[] handles = new FileHandle[relativePaths.length]; int count = 0; for (int i = 0, n = handles.length; i < n; i++) { String path = relativePaths[i]; FileHandle child = new AndroidFileHandle(assets, new File(file, path), type); if (!filter.accept(child.file())) continue; handles[count] = child; count++; } if (count < relativePaths.length) { FileHandle[] newHandles = new FileHandle[count]; System.arraycopy(handles, 0, newHandles, 0, count); handles = newHandles; } return handles; } catch (Exception ex) { throw new GdxRuntimeException("Error listing children: " + file + " (" + type + ")", ex); } } return super.list(filter); }
static private void copyDirectory (FileHandle sourceDir, FileHandle destDir) { destDir.mkdirs(); FileHandle[] files = sourceDir.list(); for (int i = 0, n = files.length; i < n; i++) { FileHandle srcFile = files[i]; FileHandle destFile = destDir.child(srcFile.name()); if (srcFile.isDirectory()) copyDirectory(srcFile, destFile); else copyFile(srcFile, destFile); } } }
static private void copyDirectory (FileHandle sourceDir, FileHandle destDir) { destDir.mkdirs(); FileHandle[] files = sourceDir.list(); for (int i = 0, n = files.length; i < n; i++) { FileHandle srcFile = files[i]; FileHandle destFile = destDir.child(srcFile.name()); if (srcFile.isDirectory()) copyDirectory(srcFile, destFile); else copyFile(srcFile, destFile); } } }
private void testClasspath () throws IOException { // no classpath support on ios if (Gdx.app.getType() == ApplicationType.iOS) return; FileHandle handle = Gdx.files.classpath("com/badlogic/gdx/utils/arial-15.png"); if (!handle.exists()) fail(); if (handle.isDirectory()) fail(); try { handle.delete(); fail(); } catch (Exception expected) { } try { handle.list(); fail(); } catch (Exception expected) { } try { handle.read().close(); fail(); } catch (Exception ignored) { } FileHandle dir = Gdx.files.classpath("com/badlogic/gdx/utils"); if (dir.isDirectory()) fail(); FileHandle child = dir.child("arial-15.fnt"); if (!child.name().equals("arial-15.fnt")) fail(); if (!child.nameWithoutExtension().equals("arial-15")) fail(); if (!child.extension().equals("fnt")) fail(); handle.read().close(); if (handle.readBytes().length != handle.length()) fail(); }
if (handle.isDirectory()) fail(); if (handle.delete()) fail(); if (handle.list().length != 0) fail(); if (handle.child("meow").exists()) fail(); if (!handle.parent().exists()) fail(); if (!handle.exists()) fail(); if (!handle.isDirectory()) fail(); if (handle.list().length != 0) fail(); handle.child("meow").mkdirs(); if (handle.list().length != 1) fail(); FileHandle child = handle.list()[0]; if (!child.name().equals("meow")) fail(); if (!child.parent().exists()) fail(); if (!new String(bytes, 0, 6).equals("moocow")) fail(); if (handle.isDirectory()) fail(); if (handle.list().length != 0) fail(); if (!handle.name().equals("meow")) fail(); if (!handle.nameWithoutExtension().equals("meow")) fail();
if (handle.isDirectory()) fail(); if (handle.delete()) fail(); if (handle.list().length != 0) fail(); if (handle.child("meow").exists()) fail(); if (!handle.parent().exists()) fail(); if (!handle.exists()) fail(); if (!handle.isDirectory()) fail(); if (handle.list().length != 0) fail(); handle.child("meow").mkdirs(); if (handle.list().length != 1) fail(); FileHandle child = handle.list()[0]; if (!child.name().equals("meow")) fail(); if (!child.parent().exists()) fail(); if (!new String(bytes, 0, 6).equals("moocow")) fail(); if (handle.isDirectory()) fail(); if (handle.list().length != 0) fail(); if (!handle.name().equals("meow")) fail(); if (!handle.nameWithoutExtension().equals("meow")) fail();
if (handle.isDirectory()) fail(); if (handle.delete()) fail(); if (handle.list().length != 0) fail(); if (handle.child("meow").exists()) fail(); if (!handle.parent().exists()) fail(); if (!handle.exists()) fail(); if (!handle.isDirectory()) fail(); if (handle.list().length != 0) fail(); handle.child("meow").mkdirs(); if (handle.list().length != 1) fail(); FileHandle child = handle.list()[0]; if (!child.name().equals("meow")) fail(); if (!child.parent().exists()) fail(); if (!new String(bytes, 0, 6).equals("moocow")) fail(); if (handle.isDirectory()) fail(); if (handle.list().length != 0) fail(); if (!handle.name().equals("meow")) fail(); if (!handle.nameWithoutExtension().equals("meow")) fail();
} catch (Exception expected) { if (handle.list().length != 0) fail("File length shouldn't be 0"); if (Gdx.app.getType() != ApplicationType.Android) { if (!handle.parent().exists()) fail("Parent doesn't exist"); if (dir.list().length == 0) fail(); FileHandle child = dir.child("badlogic.jpg"); if (!child.name().equals("badlogic.jpg")) fail();
public void purgeTempDirectory() { for (FileHandle f : Gdx.files.absolute(TEMP_DIR).list()) { f.deleteDirectory(); } }
protected void loadDirectory(FileHandle dir){ for(FileHandle handle :dir.list()){ if(handle.isDirectory()){ this.loadDirectory(handle); }else{ this.loadFile(handle); } } } protected void loadFile(FileHandle file){