List of utility methods to do Path File Name nio
String | getFileName(Path path) get File Name return path.getFileName().toString();
|
String | getFileName(String fullPath, boolean withParentFolder) get File Name Path p = Paths.get(fullPath); String file = p.getFileName().toString(); if (withParentFolder) file = p.getParent().getFileName() + "/" + file; return file; |
String | getFileName(String path) get File Name Path p = Paths.get(path); String fname = p.getFileName().toString(); int lio = fname.lastIndexOf("."); return fname.substring(0, lio); |
String | getFileName(String relativePath) get File Name Path path = Paths.get(relativePath);
return path.getFileName().toFile().getName();
|
String | getFileNameFromPath(String filePath) get File Name From Path Path p = Paths.get(filePath);
return p.getFileName().toString();
|
String | getFileNameFromPath(String str) parse the file name from file path string if (str == null || str.equals("") || str.isEmpty()) { return null; Path p = Paths.get(str); String fileName = p.getFileName().toString(); return fileName; |
String | getFilenameOrLastPath(String path) Parses a full path, returning the filename. Path p = Paths.get(path);
return p.getFileName().toString();
|
List | getFileNames(List get File Names int foundFiles = 0; try (DirectoryStream<Path> stream = Files.newDirectoryStream(dir)) { for (Path path : stream) { if (path.toFile().isDirectory()) { getFileNames(fileNames, path); } else { foundFiles++; fileNames.add(path.toAbsolutePath().toString()); ... |
List | getFileNames(List Gets all files in target directory, with the given file extension. try (DirectoryStream<Path> stream = Files.newDirectoryStream(dir)) { stream.forEach(p -> { if (p.toFile().isDirectory() && recursive) { getFileNames(fileNames, p, ext, true); } else { String fileName = p.toAbsolutePath().toString(); if (fileName.endsWith(ext)) fileNames.add(fileName); ... |
void | getFileNames(List get File Names if (!dir.toFile().isDirectory()) { fileNames.add(dir.toString()); return; try (DirectoryStream<Path> stream = Files.newDirectoryStream(dir, sFilter)) { for (Path path : stream) { fileNames.add(path.toAbsolutePath().toString()); } catch (IOException e) { e.printStackTrace(); try (DirectoryStream<Path> stream = Files.newDirectoryStream(dir)) { for (Path path : stream) { if (path.toFile().isDirectory()) { getFileNames(fileNames, path, sFilter); } catch (IOException e) { e.printStackTrace(); |