os
package os
- Alphabetic
- By Inheritance
- os
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Type Members
-
trait
BasePath extends AnyRef
A path which is either an absolute Path, a relative RelPath, or a ResourcePath with shared APIs and implementations.
A path which is either an absolute Path, a relative RelPath, or a ResourcePath with shared APIs and implementations.
Most of the filesystem-independent path-manipulation logic that lets you splice paths together or navigate in and out of paths lives in this interface
- trait BasePathImpl extends BasePath
-
case class
BasicStatInfo(size: Long, mtime: FileTime, fileType: FileType) extends Product with Serializable
The result from doing an system
staton a particular path.The result from doing an system
staton a particular path.Created via
stat! filePath.If you want more information, use
stat.full -
class
Bytes extends AnyRef
Trivial wrapper around
Array[Byte]with sane equality and useful toString -
case class
CommandResult(exitCode: Int, chunks: Seq[Either[Bytes, Bytes]]) extends Product with Serializable
Contains the accumulated output for the invocation of a subprocess command.
Contains the accumulated output for the invocation of a subprocess command.
Apart from the exit code, the primary data-structure is a sequence of byte chunks, tagged with Left for stdout and Right for stderr. This is interleaved roughly in the order it was emitted by the subprocess, and reflects what a user would have see if the subprocess was run manually.
Derived from that, is the aggregate
outanderrStreamValues, wrapping stdout/stderr respectively, and providing convenient access to the aggregate output of each stream, as bytes or strings or lines. -
sealed
trait
FilePath extends BasePath
Represents a value that is either an absolute Path or a relative RelPath, and can be constructed from a java.nio.file.Path or java.io.File
-
sealed
trait
FileType extends AnyRef
Simple enum with the possible filesystem objects a path can resolve to
-
case class
FullStatInfo(size: Long, mtime: FileTime, ctime: FileTime, atime: FileTime, group: GroupPrincipal, owner: UserPrincipal, permissions: PermSet, fileType: FileType) extends Product with Serializable
A richer, more informative version of the stat object.
A richer, more informative version of the stat object.
Created using
stat.full! filePath - type Generator[+T] = geny.Generator[T]
-
class
GlobInterpolator extends AnyRef
Lets you pattern match strings with interpolated glob-variables
-
class
Path extends FilePath with ReadablePath with BasePathImpl
An absolute path on the filesystem.
An absolute path on the filesystem. Note that the path is normalized and cannot contain any empty
"","."or".."segments - case class PathAppendRedirect(p: Path) extends ProcessOutput with Product with Serializable
- sealed trait PathConvertible[T] extends AnyRef
- case class PathRedirect(p: Path) extends ProcessInput with ProcessOutput with Product with Serializable
-
case class
PermSet(value: Int) extends Product with Serializable
A set of permissions; can be converted easily to the rw-rwx-r-x form via toString, or to a set of PosixFilePermissions via toSet and the other way via
PermSet.fromString/PermSet.fromSet -
trait
ProcessInput extends AnyRef
Represents the configuration of a SubProcess's input stream.
Represents the configuration of a SubProcess's input stream. Can either be os.Inherit, os.Pipe, os.Path or a os.Source
-
sealed
trait
ProcessOutput extends AnyRef
Represents the configuration of a SubProcess's output or error stream.
Represents the configuration of a SubProcess's output or error stream. Can either be os.Inherit, os.Pipe, os.Path or a os.ProcessOutput
- trait ReadablePath extends AnyRef
-
class
RelPath extends FilePath with BasePathImpl with SegmentedPath
A relative path on the filesystem.
A relative path on the filesystem. Note that the path is normalized and cannot contain any empty or ".". Parent ".." segments can only occur at the left-end of the path, and are collapsed into a single number ups.
-
case class
ResourceNotFoundException(path: ResourcePath) extends Exception with Product with Serializable
Thrown when you try to read from a resource that doesn't exist.
-
class
ResourcePath extends BasePathImpl with ReadablePath with SegmentedPath
Represents path to a resource on the java classpath.
Represents path to a resource on the java classpath.
Classloaders are tricky: http://stackoverflow.com/questions/12292926
-
sealed
trait
ResourceRoot extends AnyRef
Represents a possible root where classpath resources can be loaded from; either a ResourceRoot.ClassLoader or a ResourceRoot.Class.
Represents a possible root where classpath resources can be loaded from; either a ResourceRoot.ClassLoader or a ResourceRoot.Class. Resources loaded from classloaders are always loaded via their absolute path, while resources loaded via classes are always loaded relatively.
-
trait
SeekableSource extends Source
A source which is guaranteeds to provide a SeekableByteChannel
- trait SegmentedPath extends BasePath
-
case class
Shellable(value: Seq[String]) extends Product with Serializable
An implicit wrapper defining the things that can be "interpolated" directly into a subprocess call.
-
trait
Source extends AnyRef
A source of bytes; must provide either an InputStream or a SeekableByteChannel to read from.
A source of bytes; must provide either an InputStream or a SeekableByteChannel to read from. Can be constructed implicitly from strings, byte arrays, inputstreams, channels or file paths
-
case class
StatInfo(size: Long, mtime: FileTime, owner: UserPrincipal, permissions: PermSet, fileType: FileType) extends Product with Serializable
The result from doing an system
staton a particular path.The result from doing an system
staton a particular path.Created via
stat! filePath.If you want more information, use
stat.full -
trait
StreamValue extends AnyRef
Encapsulates one of the output streams from a subprocess and provides convenience methods for accessing it in a variety of forms
-
class
SubProcess extends AutoCloseable
Represents a spawn subprocess that has started and may or may not have completed.
-
case class
SubprocessException(result: CommandResult) extends Exception with Product with Serializable
Thrown when a shellout command results in a non-zero exit code.
Thrown when a shellout command results in a non-zero exit code.
Doesn't contain any additional information apart from the CommandResult that is normally returned, but ensures that failures in subprocesses happen loudly and won't get ignored unless intentionally caught
- trait WritableLowPri extends AnyRef
-
case class
proc(command: Shellable*) extends Product with Serializable
Convenience APIs around java.lang.Process and java.lang.ProcessBuilder:
Convenience APIs around java.lang.Process and java.lang.ProcessBuilder:
- os.proc.call provides a convenient wrapper for "function-like" processes that you invoke with some input, whose entire output you need, but otherwise do not have any intricate back-and-forth communication
- os.proc.stream provides a lower level API: rather than providing the output all at once, you pass in callbacks it invokes whenever there is a chunk of output received from the spawned process.
- os.proc(...) provides the lowest level API: an simple Scala API around java.lang.ProcessBuilder, that spawns a normal java.lang.Process for you to deal with. You can then interact with it normally through the standard stdin/stdout/stderr streams, using whatever protocol you want
Value Members
- val Generator: geny.Generator.type
- implicit def GlobSyntax(s: StringContext): GlobInterpolator
-
val
home: Path
The user's home directory
-
val
pwd: Path
The current working directory for this process.
- val rel: RelPath
- def resource(implicit resRoot: ResourceRoot = ...): ResourcePath
-
val
root: Path
The root of the filesystem
- val up: RelPath
-
object
/
Extractor to let you easily pattern match on os.Paths.
Extractor to let you easily pattern match on os.Paths. Lets you do
@ val base/segment/filename = pwd base: Path = Path(Vector("Users", "haoyi", "Dropbox (Personal)")) segment: String = "Workspace" filename: String = "Ammonite"
To break apart a path and extract various pieces of it.
- object BasePath
- object BasicStatInfo extends Serializable
- object FilePath
- object FileType
- object FullStatInfo extends Serializable
- object GlobInterpolator
-
object
Inherit extends ProcessInput with ProcessOutput
Inherit the input/output stream from the current process
- object Internals
- object Path
- object PathConvertible
- object PathError
- object PermSet extends Serializable
-
object
Pipe extends ProcessInput with ProcessOutput
Pipe the input/output stream to the current process to be used via
java.lang.Process#{getInputStream,getOutputStream,getErrorStream} - object ProcessInput
- object ProcessOutput
- object RelPath
- object ResourcePath
- object ResourceRoot
- object SeekableSource
- object Shellable extends Serializable
- object Source extends WritableLowPri
- object StatInfo extends Serializable
- object StreamValue
- object SubProcess
-
object
copy
Copy a file or folder from one path to another.
Copy a file or folder from one path to another. Recursively copies folders with all their contents. Errors out if the destination path already exists, or is within the source path.
-
object
exists extends (Path) ⇒ Boolean
Checks if a file or folder exists at the given path.
-
object
followLink extends (Path) ⇒ Option[Path]
Attempts to any symbolic links in the given path and return the canonical path.
Attempts to any symbolic links in the given path and return the canonical path. Returns
Noneif the path cannot be resolved (i.e. some symbolic link in the given path is broken) -
object
group extends (Path) ⇒ GroupPrincipal
Get the owning group of the file/folder at the given path
-
object
hardlink
Creates a hardlink between two paths
-
object
isDir extends (Path) ⇒ Boolean
Checks whether the given path is a directory
-
object
isFile extends (Path) ⇒ Boolean
Checks whether the given path is a regular file
-
object
isLink extends (Path) ⇒ Boolean
Checks whether the given path is a symbolic link
-
object
list extends (Path) ⇒ IndexedSeq[Path]
Returns all the files and folders directly within the given folder.
Returns all the files and folders directly within the given folder. If the given path is not a folder, raises an error. Can be called with list.stream to return an iterator. To list files recursively, use walk
For convenience
os.listsorts the entries in the folder before returning them. You can disable sorted by passing in the flagsort = false. -
object
makeDir extends (Path) ⇒ Unit
Create a single directory at the specified path.
Create a single directory at the specified path. Optionally takes in a PermSet to specify the filesystem permissions of the created directory.
Errors out if the directory already exists, or if the parent directory of the specified path does not exist. To automatically create enclosing directories and ignore the destination if it already exists, using os.makeDir.all
-
object
move
Moves a file or folder from one path to another.
Moves a file or folder from one path to another. Errors out if the destination path already exists, or is within the source path.
-
object
mtime extends (Path) ⇒ Long
Gets the mtime of the given file
-
object
owner extends (Path) ⇒ UserPrincipal
Get the owner of the file/folder at the given path
-
object
perms extends (Path) ⇒ PermSet
Get the filesystem permissions of the file/folder at the given path
-
object
read extends (ReadablePath) ⇒ String
Reads the contents of a os.Path or other os.Source as a
java.lang.String. -
object
readLink extends (Path) ⇒ FilePath
Reads the destination that the given symbolic link is pointed to
-
object
remove extends (Path) ⇒ Unit
Roughly equivalent to bash's
rm -rf.Roughly equivalent to bash's
rm -rf. Deletes any files or folders in the target path, or does nothing if there aren't any -
object
size extends (Path) ⇒ Long
Gets the size of the given file
-
object
stat extends (Path) ⇒ StatInfo
Reads in the basic filesystem metadata for the given file.
Reads in the basic filesystem metadata for the given file. By default follows symbolic links to read the metadata of whatever the link is pointing at; set
followLinks = falseto disable that and instead read the metadata of the symbolic link itself. -
object
symlink
Creates a symbolic link between two paths
-
object
temp
Alias for
java.nio.file.Files.createTempFileandjava.io.File.deleteOnExit.Alias for
java.nio.file.Files.createTempFileandjava.io.File.deleteOnExit. Pass indeleteOnExit = falseif you want the temp file to stick around. -
object
truncate
Truncate the given file to the given size.
Truncate the given file to the given size. If the file is smaller than the given size, does nothing.
-
object
walk
Recursively walks the given folder and returns the paths of every file or folder within.
Recursively walks the given folder and returns the paths of every file or folder within.
You can pass in a
skipcallback to skip files or folders you are not interested in. This can avoid walking entire parts of the folder hierarchy, saving time as compared to filtering them after the fact.By default, the paths are returned as a pre-order traversal: the enclosing folder is occurs first before any of it's contents. You can pass in
preOrder = falseto turn it into a post-order traversal, such that the enclosing folder occurs last after all it's contents.os.walkreturns but does not follow symlinks; pass infollowLinks = trueto override that behavior. You can also specify a maximum depth you wish to walk via themaxDepthparameter. -
object
write
Write some data to a file.
Write some data to a file. This can be a String, an Array[Byte], or a Seq[String] which is treated as consecutive lines. By default, this fails if a file already exists at the target location. Use write.over or write.append if you want to over-write it or add to what's already there.