Package eu.bandm.tools.util.files
Class FilenameUtils
java.lang.Object
eu.bandm.tools.util.files.FilenameUtils
Static methods for file name analysis and manipulation.
-
Method Summary
Modifier and TypeMethodDescriptiongetExtension
(File f) Returns the suffix after the last occurence of "." in the file's local name, or null if no such.getExtension
(String fn) Returns the suffix after the last occurence of ".", or null if no such.static String
Insert a string into a file name.static String
replaceExtension
(File f, @Opt String e) Replace the extension by a different one, or remove it completely.static String
replaceExtension
(String fn, @Opt String e) Replace the extension by a different one, or remove it completely.replaceUniquePlaceholder
(String in, String placeholder, String replacement) Replaces in "in" the only occurence of "placeholder" by "replacement".static String
Makes a valid URL type and unix type file name from a windows file identifier.static String
Returns the prefix of the file's local name before the last occurence of ".", or the whole string if no such.static String
stripExtension
(String fn) Returns the prefix before the last occurence of ".", or the whole string if no such.
-
Method Details
-
replaceUniquePlaceholder
@Opt public static @Opt String replaceUniquePlaceholder(String in, String placeholder, String replacement) Replaces in "in" the only occurence of "placeholder" by "replacement". Returns null if no such occurence or more than one occurence. -
getExtension
Returns the suffix after the last occurence of "." in the file's local name, or null if no such. -
getExtension
Returns the suffix after the last occurence of ".", or null if no such. -
stripExtension
Returns the prefix of the file's local name before the last occurence of ".", or the whole string if no such. -
stripExtension
Returns the prefix before the last occurence of ".", or the whole string if no such. -
multiply
Insert a string into a file name. If there are ".", then insert it directly before the last of these. Otherwise append it to the end. -
replaceExtension
Replace the extension by a different one, or remove it completely.- Parameters:
f
- must have a dot "." in its last namee
- (maybe null) replaces everything after the last dot.- Returns:
- the full canonical path of the file, with replacement applied. If e==null, then the dot is also removed.
- Throws:
IllegalArgumentException
- if the file has no dot "." in its local nameIOException
-
replaceExtension
Replace the extension by a different one, or remove it completely.- Parameters:
fn
- must contain a dot "."e
- (maybe null) replaces everything after the last dot.- Returns:
- the full canonical path of the file, with replacement applied. If e==null, then the dot is also removed.
- Throws:
IllegalArgumentException
- if the file has no dot "." in its local name
-
replaceWindowsFileSeparator
Makes a valid URL type and unix type file name from a windows file identifier. Can be applied to a file name string which has been constructed by some file choosing GUI widget from the local platform/operating system. Iff this setsFile.separatorChar == backslash
, then backslashes are contained in such a string, and are here replaced by slashes.THIS IS ONLY AN APRROXIMATION to the full conversion problem, which is very complicated and involves more transformations. See e.g the discussion on stackoverflow.com/questions/1652483.
-