FSPath queries
FSPath queries are based on XPath , the easiest way to think of how they work is to imagine the filesystem metadata as an XML document like so :
<dir name="a" lastModified="2006-01-01T00:00:00" length="11245" ....> <dir name="b"> <file name="c.txt"/> <file name="d.txt"/> </dir> </dir>
So in order to locate the file node in the above xml, you could use any of the following XPath expressions :
/dir/dir/file[@name = 'c.txt'] /dir[@name = 'a']/dir[@name = 'b']/file[1] //file[@name = 'c.txt']
The above examples are all valid FSPath queries.
FSPath functions
FSPath has all the same functions as XPath 1.0, along with an additional regex function fs:matches(String, String) .
This allows even greater power for locating files :
Consider the following :
/dir[@name = 'var']/dir[@name = 'log']//file[fs:matches(@name,'.*-[0-9]{5}.log')]
This would find all files within /var/log (or any of it's subdirectories thanks to the '//file') which had a filename with any combination of characters followed by '-' and 5 numerical characters.
File and Directory attributes
File and directory nodes have the following attributes :
canRead boolean
canWrite boolean
exists boolean
absolutePath String
canonicalPath String
name String
parent String
path String
isAbsolute boolean
isDirectory boolean
isFile boolean
isHidden boolean
lastModified Date
length long
Shorthand syntax
One major observation is that the syntax is slightly cumbersome and unnatural when it comes to expressing directory paths.
Most of us are used to seeing a directory path in the form of /user/local/bin or C:\Windows\System32
Its planned that the next release of FSPath will have a shorthand syntax for defining directory paths.
So the following query :
/dir[@name = 'usr']/dir[@name = 'local']/dir[@name = 'bin']
Could be expressed as :
/usr/local/bin