@Override public boolean isDirectory() { return base.isDirectory(); }
/** * Check if it is a file or a directory. * <code>java.nio.file.attribute.Attributes. * readBasicFileAttributes(file).isDirectory()</code> * * @param fileName the file or directory name * @return true if it is a directory */ public static boolean isDirectory(String fileName) { return FilePath.get(fileName).isDirectory(); }
private static void backupFiles(String path, String toFile) { try (OutputStream zip = FileUtils.newOutputStream(toFile, false); ZipOutputStream out = new ZipOutputStream(zip)) { FilePath p = FilePath.get(path); if (p.isDirectory()) { String pathShortName = path.replace('\\', '/'); pathShortName = pathShortName.substring(pathShortName.lastIndexOf('/') + 1); FilePath dir = FilePath.get(path); for (FilePath map : dir.newDirectoryStream()) { String entryNameBase = pathShortName + "/" + map.getName(); for (FilePath file : map.newDirectoryStream()) { backupFile(out, file.newInputStream(), entryNameBase + "/" + file.getName()); } } } else { backupFile(out, p.newInputStream(), p.getName()); } } catch (IOException e) { throw DbException.convertIOException(e, toFile); } }