1 FileName

The FileName class returns information about a file path

Return Method Description
JSFileName FileName(String filepath) Return class to get information about a file path provided as parameter
String normallize() Normalizes a path, removing double and single dot path steps. E.g.:
Path Returns
/foo// /foo/
/foo/./ /foo/
/foo/../bar /bar
/foo/../bar /bar
String getPrefix() Gets the prefix from a full file path.
String getPath() Gets the path from a full filename excluding the prefix.
String getPathNoEndSeparator() Gets the path from a full filename, which excludes the prefix, and also excluding the final directory separator.
String getFullPath() Gets the full path from a full filename, which is the prefix + path.
String getFullPathNoEndSeparator() Gets the full path from a full filename, which is the prefix + path excluding the final directory separator.
String getName() Gets the trailing name component of path.
String getBaseName() Gets the base name, minus the full path and extension, from a full filename.
String getExtension() This method returns the textual part of the filename after the last dot. There must be no directory separator after the dot.
String removeExtension() Removes the extension part from a filename, returning full filename path without extension.
String separatorsToUnix() Converts all Path separators to Unix standard separator (/).
String separatorsToWindows() Converts all Path separators to Windows standard separator (\).
String separatorsToSystem() Converts all Path separators to System standard separator.
Boolean isExtension(String extension) Checks whether the extension of the filename is that specified.
Boolean isExtension(String[] extensions) Checks whether the extension of the filename is one of the provided in parameter array of extensions.
Boolean wildcardMatch(String wildcard) Checks a filename to see if it matches the specified wildcard matcher, always testing case-sensitive.
Boolean wildcardMatchOnSystem(String wildcard) Checks a filename to see if it matches the specified wildcard matcher using the case rules of the system. E.g in Windows matching is case insensitive.

2 FileName usage examples

Next we show example of how to use FileName class:

Copy
<script>
	var filepath = new Ax.io.FileName("/data/../tmp/text_file.txt");
	
	console.log("normalize()           = " + filepath.normalize());
	console.log("getPrefix()           = " + filepath.getPrefix());
	console.log("getPath()             = " + filepath.getPath());
	console.log("getFullPath()         = " + filepath.getFullPath());
	console.log("getName()             = " + filepath.getName());
	console.log("getBaseName()         = " + filepath.getBaseName());
	console.log("getExtension()        = " + filepath.getExtension());
	console.log("removeExtension()     = " + filepath.removeExtension());
	console.log("separatorsToUnix()    = " + filepath.separatorsToUnix());
	console.log("separatorsToWindows() = " + filepath.separatorsToWindows());
	console.log("separatorsToSystem()  = " + filepath.separatorsToSystem());
	console.log("isExtension()         = " + filepath.isExtension("txt"));
	console.log("isExtension([])       = " + filepath.isExtension(["asc","txt"]));
	console.log("wildcardMatch(*.txt)  = " + filepath.wildcardMatch("*.txt"));
	console.log("wildcardMatch(*.asc)  = " + filepath.wildcardMatch("*.asc"));
	console.log("wildcardMatch(*/tex*.txt) = " + filepath.wildcardMatch("*/tex*.txt"));
</script>
normalize()           = /tmp/text_file.txt
getPrefix()           = /
getPath()             = data/../tmp/
getFullPath()         = /data/../tmp/
getName()             = text_file.txt
getBaseName()         = text_file
getExtension()        = txt
removeExtension()     = /data/../tmp/text_file
separatorsToUnix()    = /data/../tmp/text_file.txt
separatorsToWindows() = \data\..\tmp\text_file.txt
separatorsToSystem()  = /data/../tmp/text_file.txt
isExtension()         = true
isExtension([])       = true
wildcardMatch(*.txt)  = true
wildcardMatch(*.asc)  = false
wildcardMatch(*/tex*.txt) = true