_methods

trait _methods

J.Path represents a directory or file in the File.System, which may or may not exist

Path implements Idx, representing directory names hierarchy. The last name may be a name of file, if Path is for file

Path may or may not have root (like C:). This may be checked with rootOpt

A void Path has no root and zero directories

NaturalOrderingly, a 'rootless' path can be added to another path in order to extend it

Path with a root can only be extended itself

   val p1 = J.Path("aaa", "bbb").rootMake

   val p2 = J.Path("ccc", "ddd")

   p1 tp               // Prints: C:\aaa\bbb

   p2 tp               // Prints: ccc\ddd

   p1 + p2 + "xyz" tp  // Prints: C:\aaa\bbb\ccc\ddd\xyz

   p2 + p1             // App.Fail$Message: Cannot extend with root: C:\aaa\bbb
Source
_methods.scala
class java.lang.Object
trait scala.Matchable
class Any
object J.Path

Def

inline def +(v: J.Path | String): J.Path
inline def ++(v: Stream[J.Path | String]): J.Path
def contains(v: J.Path): Boolean
def contains(name: String, more: String*): Boolean
inline def delete: Boolean
def dropFirst(cnt: Int): J.Path
def dropLast(cnt: Int): J.Path
def dropRange(f: Int, sz: Int): J.Path
inline def endsWith(p: J.Path): Boolean

Checks end match

Checks end match

Returns true if this Path ends with p

   val path: J.Path = "aaa" , "bbb" + "ccc" + "ddd"

   path endsWith "ccc" , "ddd".tp // Prints: true

   path endsWith "aaa" , "bbb".tp // Prints: false
Source
_methods.scala
inline def exists: Boolean

Check exists

Check exists

Returns true this Path exists in the file system as file or directory

Source
_methods.scala
def file: J.File
def fileOpt: Opt[J.File]

Sub-path index

Sub-path index

Optionally returns matching sub-path start index

  val path: J.Path = "aaa" , "bbb" + "ccc" + "ddd" + "eee"

  path indexOpt "ccc" , "ddd" tp  // Prints: Opt(2)

  path indexOpt "ddd" , "ccc" tp  // Prints: Opt(VOID)
Source
_methods.scala
inline def isDirectory: Boolean
inline def isEmpty: Boolean
inline def isFile: Boolean
def join(v: J.Path | String): J.Path
def joinAll(v: Stream[J.Path | String]): J.Path
inline def lastName: String

Last name

Last name

Returns last name in the Path hierarchy

If this Path points to a file, lastName is the name of file

   val path : J.Path =  "Temp" , "Test.txt"

   path.lastName tp  // Prints: Test.txt
Source
_methods.scala
def make: Unit
def name(idx: Int): String
inline def names: Idx[String]
inline def parent: J.Path

Parent Path

Parent Path

Returns parent Path of this Path

  val p: J.Path = "aaa" , "bbb" + "ccc"

  p.parent tp  // Prints: aaa\bbb
Source
_methods.scala
def root: J.Path

Root path

Root path

Returns root Path

Note: Fails if no root available

  J.Path.get.root.tp // May print: C:\
Source
_methods.scala

Looses root if any

Looses root if any

If this Path has a root, new Path without root is returned

Otherwise this Path is returned as is

  val p = J.Path("aaa" , "bbb").rootMake

  p tp           // May print: C:\aaa\bbb

  p.rootDrop tp  // May print: aaa\bbb
Source
_methods.scala

Makes root if none

Makes root if none

If this Path has no root, new Path with current root is returned

Otherwise this Path is returned as is

 val p: J.Path = "aaa" , "bbb"

 p tp           // May print: aaa\bbb

 p.rootMake tp  // May print: C:\aaa\bbb
Source
_methods.scala

Optional root

Optional root

Optionally returns root Path if available

 val p = J.Path("aaa" , "bbb").rootMake

 p.rootOpt tp           // May print: Opt(C:\)

 p.rootDrop.rootOpt.tp //     prints: Opt(VOID)
Source
_methods.scala
def size: Int
inline def startsWith(p: J.Path): Boolean

Checks start match

Checks start match

Returns true if this Path starts with p

   val path: J.Path = "aaa" , "bbb" + "ccc" + "ddd"

   path startsWith "aaa" , "bbb" tp  // Prints: true

   path startsWith "bbb" , "aaa" tp  // Prints: false
Source
_methods.scala
def takeAfter(p: J.Path, dflt: J.Path): J.Path

Sub-path after

Sub-path after

Returns sub-path after p

Value Params
default

path if p is not found. If not specified, default is the original path

  val p: J.Path = "aaa" , "bbb" + "ccc" + "ddd" + "eee" + "fff"
  p tp                                              // Prints: aaa\bbb\ccc\ddd\eee\fff
  p subpathAfter "ccc" , "ddd" tp                   // Prints: eee\fff
  p subpathAfter "ddd" , "ccc" tp                   // Prints: aaa\bbb\ccc\ddd\eee\fff
  p subpathAfter ("ddd" , "ccc", "xyz" , "bbc") tp  // Prints: xyz\bbc
p

sub-path to copy after

Source
_methods.scala
def takeBefore(p: J.Path, dflt: J.Path): J.Path

Sub-path before

Sub-path before

Returns sub-path from start to p

Value Params
default

path if p is not found. If not specified, default is the original path

  val p: J.Path = "aaa" , "bbb" + "ccc" + "ddd" + "eee" + "fff"
  p tp                                            // Prints: aaa\bbb\ccc\ddd\eee\fff
  p subpathBefore "ccc" , "ddd" tp                   // Prints: aaa\bbb
  p subpathBefore "ddd" , "ccc" tp                   // Prints: aaa\bbb\ccc\ddd\eee\fff
  p subpathBefore ("ddd" , "ccc", "xyz" , "bbc") tp  // Prints: xyz\bbc
p

sub-path to copy up to

Source
_methods.scala
def takeFirst(cnt: Int): J.Path
def takeFrom(p: J.Path, dflt: J.Path): J.Path

Sub-path from

Sub-path from

Returns sub-path starting from specified Path

Value Params
default

path if p is not found. If not specified, default is the original path

  val p: J.Path = "aaa" , "bbb" + "ccc" + "ddd" + "eee" + "fff"
  p tp                                         // Prints: aaa\bbb\ccc\ddd\eee\fff
  p subpathFrom "ccc" , "ddd" tp                  // Prints: ccc\ddd\eee\fff
  p subpathFrom "ddd" , "ccc" tp                  // Prints: aaa\bbb\ccc\ddd\eee\fff
  p subpathFrom ("ddd" , "ccc", "xyz" , "bbc").tp // Prints: xyz\bbc
p

sub-path to copy from

Source
_methods.scala
def takeLast(cnt: Int): J.Path
def takeRange(start: Int, size: Int): J.Path