public boolean isDirectory () { if (type == FileType.Internal) { try { return assets.list(file.getPath()).length > 0; } catch (IOException ex) { return false; } } return super.isDirectory(); }
public boolean isDirectory () { if (type == FileType.Internal) { try { return assets.list(file.getPath()).length > 0; } catch (IOException ex) { return false; } } return super.isDirectory(); }
private FileHandle getZipFileHandleIfExists (FileHandle handle, String path) { try { assets.open(path).close(); // Check if file exists. return handle; } catch (Exception ex) { // try APK expansion instead FileHandle zipHandle = new AndroidZipFileHandle(path); if (!zipHandle.isDirectory()) return zipHandle; else if (zipHandle.exists()) return zipHandle; } return handle; }
private FileHandle getZipFileHandleIfExists (FileHandle handle, String path) { try { assets.open(path).close(); // Check if file exists. return handle; } catch (Exception ex) { // try APK expansion instead FileHandle zipHandle = new AndroidZipFileHandle(path); if (!zipHandle.isDirectory()) return zipHandle; else if (zipHandle.exists()) return zipHandle; } return handle; }
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); } } } } }
/** Copies this file or directory to the specified file or directory. If this handle is a file, then 1) if the destination is a * file, it is overwritten, or 2) if the destination is a directory, this file is copied into it, or 3) if the destination * doesn't exist, {@link #mkdirs()} is called on the destination's parent and this file is copied into it with a new name. If * this handle is a directory, then 1) if the destination is a file, GdxRuntimeException is thrown, or 2) if the destination is * a directory, this directory is copied into it recursively, overwriting existing files, or 3) if the destination doesn't * exist, {@link #mkdirs()} is called on the destination and this directory is copied into it recursively. * @throws GdxRuntimeException if the destination file handle is a {@link FileType#Classpath} or {@link FileType#Internal} * file, or copying failed. */ public void copyTo (FileHandle dest) { if (!isDirectory()) { if (dest.isDirectory()) dest = dest.child(name()); copyFile(this, dest); return; } if (dest.exists()) { if (!dest.isDirectory()) throw new GdxRuntimeException("Destination exists but is not a directory: " + dest); } else { dest.mkdirs(); if (!dest.isDirectory()) throw new GdxRuntimeException("Destination directory cannot be created: " + dest); } copyDirectory(this, dest.child(name())); }
/** Copies this file or directory to the specified file or directory. If this handle is a file, then 1) if the destination is a * file, it is overwritten, or 2) if the destination is a directory, this file is copied into it, or 3) if the destination * doesn't exist, {@link #mkdirs()} is called on the destination's parent and this file is copied into it with a new name. If * this handle is a directory, then 1) if the destination is a file, GdxRuntimeException is thrown, or 2) if the destination is * a directory, this directory is copied into it recursively, overwriting existing files, or 3) if the destination doesn't * exist, {@link #mkdirs()} is called on the destination and this directory is copied into it recursively. * @throws GdxRuntimeException if the destination file handle is a {@link FileType#Classpath} or {@link FileType#Internal} * file, or copying failed. */ public void copyTo (FileHandle dest) { if (!isDirectory()) { if (dest.isDirectory()) dest = dest.child(name()); copyFile(this, dest); return; } if (dest.exists()) { if (!dest.isDirectory()) throw new GdxRuntimeException("Destination exists but is not a directory: " + dest); } else { dest.mkdirs(); if (!dest.isDirectory()) throw new GdxRuntimeException("Destination directory cannot be created: " + dest); } copyDirectory(this, dest.child(name())); }
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); } } }
/** Moves this file to the specified file, overwriting the file if it already exists. * @throws GdxRuntimeException if the source or destination file handle is a {@link FileType#Classpath} or * {@link FileType#Internal} file. */ public void moveTo (FileHandle dest) { switch (type) { case Classpath: throw new GdxRuntimeException("Cannot move a classpath file: " + file); case Internal: throw new GdxRuntimeException("Cannot move an internal file: " + file); case Absolute: case External: // Try rename for efficiency and to change case on case-insensitive file systems. if (file().renameTo(dest.file())) return; } copyTo(dest); delete(); if (exists() && isDirectory()) deleteDirectory(); }
/** Moves this file to the specified file, overwriting the file if it already exists. * @throws GdxRuntimeException if the source or destination file handle is a {@link FileType#Classpath} or * {@link FileType#Internal} file. */ public void moveTo (FileHandle dest) { switch (type) { case Classpath: throw new GdxRuntimeException("Cannot move a classpath file: " + file); case Internal: throw new GdxRuntimeException("Cannot move an internal file: " + file); case Absolute: case External: // Try rename for efficiency and to change case on case-insensitive file systems. if (file().renameTo(dest.file())) return; } copyTo(dest); delete(); if (exists() && isDirectory()) deleteDirectory(); }
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(); }
handle.delete(); if (handle.exists()) fail(); if (handle.isDirectory()) fail(); if (handle.delete()) fail(); if (handle.list().length != 0) fail(); if (!handle.isDirectory()) fail(); if (handle.list().length != 0) fail(); handle.child("meow").mkdirs(); input.close(); 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(); handle.deleteDirectory(); if (handle.exists()) fail(); if (handle.isDirectory()) fail(); handle.delete(); handle.deleteDirectory();
handle.delete(); if (handle.exists()) fail(); if (handle.isDirectory()) fail(); if (handle.delete()) fail(); if (handle.list().length != 0) fail(); if (!handle.isDirectory()) fail(); if (handle.list().length != 0) fail(); handle.child("meow").mkdirs(); input.close(); 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(); handle.deleteDirectory(); if (handle.exists()) fail(); if (handle.isDirectory()) fail(); handle.delete(); handle.deleteDirectory();
handle.delete(); if (handle.exists()) fail(); if (handle.isDirectory()) fail(); if (handle.delete()) fail(); if (handle.list().length != 0) fail(); if (!handle.isDirectory()) fail(); if (handle.list().length != 0) fail(); handle.child("meow").mkdirs(); input.close(); 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(); handle.deleteDirectory(); if (handle.exists()) fail(); if (handle.isDirectory()) fail(); handle.delete(); handle.deleteDirectory();
private void testInternal () throws IOException { FileHandle handle = Gdx.files.internal("data/badlogic.jpg"); if (!handle.exists()) fail("Couldn't find internal file"); if (handle.isDirectory()) fail("Internal file shouldn't be a directory"); try { handle.delete(); if (!dir.exists()) fail(); if (!dir.isDirectory()) fail(); if (dir.list().length == 0) fail(); FileHandle child = dir.child("badlogic.jpg");
@Override protected boolean validate (String input) { FileHandle file = Gdx.files.absolute(input); return file.exists() && file.isDirectory(); } }
@Override protected boolean validate (String input) { FileHandle file = Gdx.files.absolute(input); if (file.exists() == false || file.isDirectory() == false) return false; if (mustBeEmpty) { return file.list().length == 0; } else { return file.list().length != 0; } }
@Override public void clicked (InputEvent event, float x, float y) { super.clicked(event, x, y); if (getTapCount() == 2 && selectedItems.contains(FileItem.this, true)) { if (file.isDirectory()) { setDirectory(file, HistoryPolicy.ADD); } else selectionFinished(); } }
private FileHandleMetadata (FileHandle file) { this.name = file.name(); this.directory = file.isDirectory(); this.lastModified = file.lastModified(); this.length = file.length(); this.readableFileSize = FileUtils.readableFileSize(length); }