List of utility methods to do Path File Extention nio
String | getFileNameWithoutExtension(Path path) Gets the file name of the given path without the extension. String name = path.getFileName().toString(); int index = name.lastIndexOf('.'); if (index <= 0) { return name; } else { return name.substring(0, index); |
String | getFileNameWithoutExtension(Path path) get File Name Without Extension if (path == null || Files.isDirectory(path)) { return null; String fileName = path.getFileName().toString(); return fileName.substring(0, fileName.lastIndexOf(".")); |
String | getFileNameWithoutExtension(String filePath) get File Name Without Extension String name = getFileName(filePath); return name.replaceFirst("[.][^.]+$", ""); |
List | getFilesList(Path directory, Set get Files List try (Stream<Path> stream = Files.list(directory)) { List<Path> list = stream.filter(path -> extensions.contains(getFileExtension(path))) .collect(Collectors.toList()); return list; |
String | getFullNameWithoutExtension(Path f) get Full Name Without Extension String path = f.toString();
return getFullNameWithoutExtension(path);
|
String | getLeafName(Path path, boolean includeExtension) get Leaf Name return getLeafName(path.toString(), includeExtension);
|
List | getListOfFilesByExtension(Path directoryPath, Set get List Of Files By Extension List<Path> result = new ArrayList<>(); DirectoryStream.Filter<Path> filter = (fileEntry) -> { return extensions.contains(com.google.common.io.Files.getFileExtension(fileEntry.toString())); }; try (DirectoryStream<Path> stream = Files.newDirectoryStream(directoryPath, filter)) { for (Path file : stream) { result.add(file); return result; |
Path | getPath(String outputDir, String qualifiedFilename, String fileextension) get Path String[] pathParts = qualifiedFilename.split("\\."); pathParts[pathParts.length - 1] = pathParts[pathParts.length - 1] + "." + fileextension; return FileSystems.getDefault().getPath(outputDir, pathParts); |
String | getTransformedOutputPath(Path input, String compressExtension, String outputDir) get Transformed Output Path return Paths.get(outputDir).resolve(input) + ".variants.json" + compressExtension; |
boolean | hasExtensionIgnoreCase(Path path, String ext) has Extension Ignore Case String name = path.getFileName().toString(); int dot = name.lastIndexOf('.'); String token = name.substring(dot + 1); if (token == null) return false; return token.equalsIgnoreCase(ext); |