absolute, normalized path
absolute, normalized path
appends the given content to the file
appends the given content to the file
the file are open with the APPEND
option.
appends the given bytes to the file
appends the given bytes to the file
the file are open with the APPEND
option.
appends the given content, separated with new-lines to the file
appends the given content, separated with new-lines to the file
the file are open with the APPEND
option.
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*)*
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 exists
try to read the file line by line and execute the give function for each line
try to read the file line by line and execute the give function for each line
function which are called for each line
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
memory constant operation to process all lines
memory constant operation to process all lines
character set
a per line iterator
get entry permission mode
get entry permission mode
maps a given function over every line from the given file
maps a given function over every line from the given file
function which are called for each line
a per line iterator where for each line 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
try to read the whole file at once and return it as a string.
try to read the whole file at once and return it as a string.
use sclib.io.fs.FSFile.lines(cs:java\.nio\.charset\.Charset)* for a memory constant operation.
character set
whole file content as a string
try to read the whole binary file
try to read the whole binary file
whole file content as a byte array
write the given content to the file
write the given content to the file
when the options
doesn't contain the APPEND
option, the file are opened
with the TRUNCATE_EXISTING
option which truncate's the file before writing.
write the given bytes to the file
write the given bytes to the file
when the options
doesn't contain the APPEND
option, the file are opened
with the TRUNCATE_EXISTING
option which truncate's the file before writing.
write the given content, separated with new-lines to the file
write the given content, separated with new-lines to the file
Represents a 'File'
the functions
write
,writeLines
,append
andappendLines
expects a type-class instance (from Writable) for their to be written payload in scope. instances forstring
,char
,short
,int
,long
,float
,double
and some collection types are already defined (see Writable$).the
write
andappend
functions don't add a newline at the end / between the sequences. for functions which add newlines usewriteLines
andappendLines
.check the member documentation for examples