underlying path
absolute, normalized path
set entry permission mode
set entry permission mode
: list of unix like symbolic permissions notation
chmod("a=r,u+w") -> chmod(Seq(OWNER_READ, OWNER_WRITE, GROUP_READ, OTHERS_READ)) chmod("a+x") -> current permissions + Seq(OWNER_EXECUTE, GROUP_EXECUTE, OTHERS_EXECUTE)
set entry permission mode
set entry permission mode
: unix like file permission notation
chmod(700) -> chmod(Seq(OWNER_READ, OWNER_WRITE, OWNER_EXECUTE)) chmod(644) -> chmod(Seq(OWNER_READ, OWNER_WRITE, GROUP_READ, OTHERS_READ))
set entry permission mode
set entry permission mode
: sequence of http://http://docs.oracle.com/javase/8/docs/api/java/nio/file/attribute/PosixFilePermission.html
scala> import java.nio.file.attribute.PosixFilePermission._ scala> for { | wd <- dir("sclib-example") | wd <- wd.createTemp | fh <- file(wd, "a-file").flatMap(_.create) | _ <- fh.chmod(OWNER_READ) | mod <- fh.lsmod | _ <- wd.deleteR() | } yield mod res0: scala.util.Try[Seq[java.nio.file.attribute.PosixFilePermission]] = Success(List(OWNER_READ))
set entry permission mode recursive
set entry permission mode recursive
fail on any error
set entry permission mode recursive
set entry permission mode recursive
fail on any error
set entry permission mode recursive
set entry permission mode recursive
fail on any error
copy the entry (file -> file, dir -> dir)
copy the entry (file -> file, dir -> dir)
scala> for { | wd <- dir("sclib-example") | wd <- wd.createTemp | src <- file(wd, "a-file") | _ <- src.write("content") | dst <- file(wd, "b-file") | _ <- src.copy(dst) | c <- dst.slurp | _ <- wd.deleteR | } yield c res0: scala.util.Try[String] = Success(content)
copy the entry to the given dir
copy the entry to the given dir
if the target dir doesn't exists, it's being created
use FSEntry.copyToR(target* for a recursive copy operation
recursively copy the entry to the given dir
recursively copy the entry to the given dir
if the target dir doesn't exists, it's being created
create the filesystem entry with the given permissions
create the filesystem entry with the given permissions
the path hierarchy must exist - use FSEntry.mkDirs(attrs: FileAttribute*) to create the hierarchy at first.
unix like symbolic mode
create("a=r,u+w") -> create the entry with the PosixFilePermissions: OWNER_READ, OWNER_WRITE, GROUP_READ and OTHERS_READ scala> import scala.collection.SortedSet scala> for { | wd <- dir("/tmp/sclib") | wd <- wd.createTemp | fh <- file(wd, "example") | _ <- fh.create("a=r,u+wx") | perm <- fh.lsmod | _ <- wd.deleteR | } yield perm.to[SortedSet] res0: scala.util.Try[scala.collection.SortedSet[java.nio.file.attribute.PosixFilePermission]] = Success(TreeSet(OWNER_READ, OWNER_WRITE, OWNER_EXECUTE, GROUP_READ, OTHERS_READ))
create the filesystem entry with the given permissions
create the filesystem entry with the given permissions
the path hierarchy must exist - use FSEntry.mkDirs(attrs: FileAttribute*) to create the hierarchy at first.
unix like numeric mode
scala> import scala.collection.SortedSet scala> for { | wd <- dir("/tmp/sclib") | wd <- wd.createTemp | fh <- file(wd, "example") | _ <- fh.create(740) | perm <- fh.lsmod | _ <- wd.deleteR | } yield perm.to[SortedSet] res0: scala.util.Try[SortedSet[java.nio.file.attribute.PosixFilePermission]] = Success(TreeSet(OWNER_READ, OWNER_WRITE, OWNER_EXECUTE, GROUP_READ))
create the filesystem entry with the given permissions
create the filesystem entry with the given permissions
the path hierarchy must exist - use FSEntry.mkDirs(attrs:java\.nio\.file\.attribute\.FileAttribute[_]*)* to create the hierarchy at first.
create the filesystem entry with default permissions
create the filesystem entry with default permissions
the path hierarchy must exist - use FSEntry.mkDirs(attrs:java\.nio\.file\.attribute\.FileAttribute[_]*)* to create the hierarchy at first.
create a new temporary filesystem entry.
create a new temporary filesystem entry. the actual name is used for the prefix.
if no absolute path is given, the entry is created in the temp directory (determined by: System.getProperty("java.io.tmpdir")).
scala> for { | fh <- dir("a-temp-dir") | // override the original fh | fh <- fh.createTemp | _ <- fh.delete | // fh.name is something like 'a-temp-dir7526811586167481701' | } yield fh.name.matches("a-temp-dir\\d+") res0: scala.util.Try[Boolean] = Success(true) scala> for { | fh <- file("a-temp-file") | // override the original fh | fh <- fh.createTemp | _ <- fh.delete | // fh.name is something like 'a-temp-file9014711075515420555' | } yield fh.name.matches("a-temp-file\\d+") res0: scala.util.Try[Boolean] = Success(true) scala> for { | fh <- file("a-temp-file.txt") | // override the original fh | fh <- fh.createTemp | _ <- fh.delete | // fh.name is something like 'a-temp-file2068553337840465580.txt' | } yield fh.name.matches("a-temp-file\\d+\\.txt") res1: scala.util.Try[Boolean] = Success(true)
delete the file
delete the file
returns a Failure
if the file doesn't exist.
delete the file if it exists
delete the file if it exists
true
if the file was deleted, false
if it doesn't exist.
relative depth to a given FSEntry
relative depth to a given FSEntry
scala> for { | a <- dir("sclib-example") | b <- dir(a, "x/y/z/..") | } yield a.depth(b) res0: scala.util.Try[Int] = Success(2)
check if the file exists
check if the file is a directory
check if the file is a regular file
get entry permission mode
create the directories
create the directories
- when called on a FSDir
, the directroy's path (inclusive parents) are created
- when called on a FSFile
the parent hierarchy are created
move the entry
move the entry
move the entry to the given directory, and keep the name
move the entry to the given directory, and keep the name
set the modification time
set the modification time
file modification time in milliseconds, since the epoch (1970-01-01T00:00:00Z)
file modification time in milliseconds, since the epoch (1970-01-01T00:00:00Z)
file / directory name
rename the entry
rename the entry
scala> for { | wd <- dir("sclib-example") | wd <- wd.createTemp | src <- file(wd, "a-file") | _ <- src.create | dst <- src.renameTo("b-file") | res = (src.exists, dst.exists) | _ <- wd.deleteR | } yield res res0: scala.util.Try[(Boolean, Boolean)] = Success((false,true))
file size in bytes
File System Entry