absolute, normalized 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
FSEntry.chmod(perms:java\.nio\.file\.attribute\.PosixFilePermission*)*
scala> import sclib.io.fs._ scala> import scala.util.Success scala> import scala.collection.SortedSet scala> dir("wd").flatMap(_.createTemp).map{ wd => | // | // create some files - some with a 'f' prefix, others with a 'h' prefix | List("f1", "h2", "f3", "h4", "f5").map(file(wd, _).flatMap(_.create)) | // | // create some directories | List("fd1", "hd2", "fd3", "hd4", "fd5").map(dir(wd, _).flatMap(_.create)) | // | // collect only files, which doesn't have a 'h' prefix | val fileNames = wd.collectR{ | case Success(f: FSFile) if ! f.name.startsWith("h") => f.name | }.toList | // | // cleanup | wd.deleteR() | // | fileNames.to[SortedSet] | } res0: scala.util.Try[SortedSet[String]] = Success(TreeSet(f1, f3, f5))
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.
delete the directory recursive
delete the directory recursive
this function is NOT atomic - when a error occurs, it returns a Failure
but the
successful deleted files are lost.
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 exists
apply the given function recursive to every FSEntry
start from this directory
apply the given function recursive to every FSEntry
start from this directory
a Iterator
where for each entry the given function was applied
apply the given function recursive to every FSEntry
start from this directory
check if the file is a directory
check if the file is a directory
check if the file is a regular file
check if the file is a regular file
recursive directory content, start from this directory.
recursive directory content, start from this directory.
shortcut to use without parenthesize
to control the depth, use FSDir.lsR(depth:Int)*
recursive directory content, start from this directory.
recursive directory content, start from this directory.
maximum depth level
a Iterator
with the directory entries
get entry permission mode
get entry permission mode
apply the given function recursive to every FSEntry
start from this directory
apply the given function recursive to every FSEntry
start from this directory
a Iterator
where for each entry the given function was applied
FSEntry.mkDirs(attrs:java\.nio\.file\.attribute\.FileAttribute[_]*)*
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 modification time in milliseconds, since the epoch (1970-01-01T00:00:00Z)
file / directory name
file / directory name
underlying path
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 size in bytes
Represents a 'Directory'
to iterate over a directory tree, there are the following functions available:
the method signature from
foreach
,map
andflatMap
shown here are simplifiedthis functions doesn't work recursive by default. for a recursive behaviour, use their counterpart functions with the 'R' suffix:
lsR
,foreachR
,mapR
orcollectR
.to control the recursive level, you can give the
lsR
,foreachR
,mapR
orcollectR
function a 'depth' argument.iterate over a directory tree
you can give
foreach
,map
andflatMap
a traverse function which receives aFSEntryImpl
or aTry[FSEntryImpl]
.assume the following directory tree:
fail on first error: if you get it a function which receives a
FSEntryImpl
and an exception occurs, the function execution stops and aFailure
are returned.exceptions intercepted: if you get it a function which receives a
Try[FSEntryImpl]
and an exception occurs, the function execution continues.check the member documentation for examples