grizzled.file

util

object util

Useful file-related utility functions.

Linear Supertypes
AnyRef, Any
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. util
  2. AnyRef
  3. Any
  1. Hide All
  2. Show all
Learn more about member selection
Visibility
  1. Public
  2. All

Value Members

  1. final def !=(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  2. final def !=(arg0: Any): Boolean

    Definition Classes
    Any
  3. final def ##(): Int

    Definition Classes
    AnyRef → Any
  4. final def ==(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  5. final def ==(arg0: Any): Boolean

    Definition Classes
    Any
  6. final def asInstanceOf[T0]: T0

    Definition Classes
    Any
  7. def basename(path: String, fileSep: String = fileSeparator): String

    Get the basename (file name only) part of a path.

    Get the basename (file name only) part of a path.

    path

    the path (absolute or relative)

    fileSep

    the file separator to use. Defaults to the value of the "file.separator" property.

    returns

    the file name portion

  8. def clone(): AnyRef

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  9. def copy(file: String, targetDir: String): Try[Boolean]

    Copy a file to a directory.

    Copy a file to a directory. If the target directory does not exist, it is created.

    file

    Path name of the file to copy

    targetDir

    Path name to target directory

    returns

    Success(true) if the copy worked. Failure(exception) on error.

  10. def copy(file: String, targetDir: String, createTarget: Boolean): Try[Boolean]

    Copy a file to a directory.

    Copy a file to a directory.

    file

    Path name of the file to copy

    targetDir

    Path name to target directory

    createTarget

    true to create the target directory, false to throw an exception if the directory doesn't already exist.

    returns

    Success(true) if the copy worked. Failure(exception) on error.

  11. def copy(files: Iterable[String], targetDir: String, createTarget: Boolean = true): Try[Boolean]

    Copy multiple files to a target directory.

    Copy multiple files to a target directory. Also see the version of this method that takes only one file.

    files

    An Iterable of file names to be copied

    targetDir

    Path name to target directory

    createTarget

    true to create the target directory, false to throw an exception if the directory doesn't already exist.

    returns

    Success(true) if the copy worked. Failure(exception) on error.

  12. def copyFile(source: File, target: File): Try[File]

    Copy a source file to a target file, using binary copying.

    Copy a source file to a target file, using binary copying. The source file must be a file. The target path can be a file or a directory; if it is a directory, the target file will have the same base name as as the source file.

    source

    path to the source file

    target

    path to the target file or directory

    returns

    A Success containing the full path of the target file, or Failure(exception)

  13. def copyFile(sourcePath: String, targetPath: String): Try[String]

    Copy a source file to a target file, using binary copying.

    Copy a source file to a target file, using binary copying. The source file must be a file. The target path can be a file or a directory; if it is a directory, the target file will have the same base name as as the source file.

    sourcePath

    path to the source file

    targetPath

    path to the target file or directory

    returns

    A Success with the full path of the target file, or Failure(exception)

  14. def copyTree(sourceDir: File, targetDir: File): Try[Boolean]

    Recursively copy a source directory and its contents to a target directory.

    Recursively copy a source directory and its contents to a target directory. Creates the target directory if it does not exist.

    sourceDir

    the source directory

    targetDir

    the target directory

    returns

    Success(true) if the copy worked. Failure(exception) on error.

  15. def copyTree(sourceDir: String, targetDir: String): Try[Boolean]

    Recursively copy a source directory and its contents to a target directory.

    Recursively copy a source directory and its contents to a target directory. Creates the target directory if it does not exist.

    sourceDir

    the source directory

    targetDir

    the target directory

    returns

    Success(true) if the copy worked. Failure(exception) on error.

  16. def createTemporaryDirectory(prefix: String, maxTries: Int = 3): File

    Create a temporary directory.

    Create a temporary directory.

    prefix

    Prefix for directory name

    maxTries

    Maximum number of times to try creating the directory before giving up.

    returns

    the directory. Throws an IOException if it can't create the directory.

  17. def deleteTree(dir: File): Try[Int]

    Recursively remove a directory tree.

    Recursively remove a directory tree. This function is conceptually equivalent to rm -r on a Unix system.

    dir

    The directory

    returns

    Failure(exception) on error, Success(total) on success. total is the total number of deleted files.

  18. def deleteTree(dir: String): Unit

    Recursively remove a directory tree.

    Recursively remove a directory tree. This function is conceptually equivalent to rm -r on a Unix system.

    dir

    The directory

  19. def dirname(path: String, fileSep: String = fileSeparator): String

    Get the directory name of a pathname.

    Get the directory name of a pathname.

    path

    path (absolute or relative)

    fileSep

    the file separator to use. Defaults to the value of the "file.separator" property.

    returns

    the directory portion

  20. def dirnameBasename(path: String, fileSep: String = fileSeparator): (String, String)

    Split a path into directory (dirname) and file (basename) components.

    Split a path into directory (dirname) and file (basename) components. Analogous to Python's os.path.pathsplit() function.

    path

    the path to split

    fileSep

    the file separator to use. Defaults to the value of the "file.separator" property.

    returns

    a (dirname, basename) tuple of strings

  21. def dirnameBasenameExtension(pathname: String, fileSep: String = fileSeparator): (String, String, String)

    Split a pathname into the directory name, basename, and extension pieces.

    Split a pathname into the directory name, basename, and extension pieces.

    pathname

    the pathname

    fileSep

    the file separator to use. Defaults to the value of the "file.separator" property.

    returns

    a 3-tuple of (dirname, basename, extension)

  22. def eglob(pattern: String): List[String]

    An extended glob function that supports all the wildcards of the glob() function, in addition to:

    An extended glob function that supports all the wildcards of the glob() function, in addition to:

    • a leading ~, signifying the user's home directory
    • a special ** wildcard that recursively matches any directory. (Think "ant".)

    ~user is not supported, however.

    pattern

    the wildcard pattern

    returns

    list of matches, or an empty list for none

  23. final def eq(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  24. def equals(arg0: Any): Boolean

    Definition Classes
    AnyRef → Any
  25. val fileSeparator: String

  26. val fileSeparatorChar: Char

  27. def finalize(): Unit

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  28. def fnmatch(name: String, pattern: String): Boolean

    Similar to Python's fnmatch() function, this function determines whether a string matches a wildcard pattern.

    Similar to Python's fnmatch() function, this function determines whether a string matches a wildcard pattern. Patterns are Unix-style shell-style wildcards:

    • * matches everything
    • ? matches any single character
    • [set] matches any character in set
    • [!set] matches any character not in set

    An initial period in filename is not special. Matches are case-sensitive on Posix operating systems, case-insensitive elsewhere.

    name

    the name to match

    pattern

    the wildcard pattern

  29. final def getClass(): Class[_]

    Definition Classes
    AnyRef → Any
  30. def glob(path: String): List[String]

    Return a list of paths matching a pathname pattern.

    Return a list of paths matching a pathname pattern. The pattern may contain simple shell-style wildcards. See fnmatch(). This function is essentially a direct port of the Python glob.glob() function.

    Restrictions:

    - There's currently no way to escape a wildcard character. That is, if you need to match a '*' character or a '?' character exactly, you can't do that with this library. (You can't do it with the glob library in Python 2 or Python 3, either.)

    path

    The path to expand.

    returns

    a list of possibly expanded file names

  31. def hashCode(): Int

    Definition Classes
    AnyRef → Any
  32. final def isInstanceOf[T0]: Boolean

    Definition Classes
    Any
  33. def joinPath(pieces: File*): File

    Join components of a path together, using the file separator of the currently running system

    Join components of a path together, using the file separator of the currently running system

    pieces

    path pieces

    returns

    a composite path

  34. def joinPath(pieces: String*): String

    Join components of a path together, using the file separator of the currently running system

    Join components of a path together, using the file separator of the currently running system

    pieces

    path pieces

    returns

    a composite path

  35. def joinPath(fileSep: String, pieces: List[String]): String

    Join components of a path together.

    Join components of a path together.

    fileSep

    the file separator to use

    pieces

    path pieces

    returns

    a composite path

  36. def listRecursively(file: File, topdown: Boolean = true): Stream[File]

    List a directory recursively, returning File objects for each file (and subdirectory) found.

    List a directory recursively, returning File objects for each file (and subdirectory) found. This method does lazy evaluation, instead of calculating everything up-front, as walk() does.

    file

    The File object, presumed to represent a directory.

    topdown

    If true (the default), the stream will be generated top down. If false, it'll be generated bottom-up.

    returns

    a stream of File objects.

  37. def nativePath(path: String): String

    Converts a path name from universal path notation to the operating system-specific format.

    Converts a path name from universal path notation to the operating system-specific format. Universal path notation always uses a Unix-style "/" to separate path elements. A native path can be converted to a universal path via the universal_path() function. Note that on POSIX-compliant systems, this function simply returns the path parameter unmodified.

    path

    the path to convert from universtal to native path notation

    returns

    the native path

  38. final def ne(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  39. def normalizePath(path: String): String

    Normalize a path, eliminating double slashes, resolving embedded ".

    Normalize a path, eliminating double slashes, resolving embedded ".." strings (e.g., "/foo/../bar" becomes "/bar"), etc. Works for Windows and Posix operating systems.

    path

    the path

    returns

    the normalized path

  40. def normalizePosixPath(path: String): String

    Adapted from the Python version of normpath() in Python's os.posixpath module.

    Adapted from the Python version of normpath() in Python's os.posixpath module.

    path

    the path

    returns

    the normalized path

  41. def normalizeWindowsPath(path: String): String

    Normalize a Windows path name.

    Normalize a Windows path name. Handles UNC paths. Adapted from the Python version of normpath() in Python's os.ntpath module.

    path

    the path

    returns

    the normalized path

  42. final def notify(): Unit

    Definition Classes
    AnyRef
  43. final def notifyAll(): Unit

    Definition Classes
    AnyRef
  44. def pwd: String

    Return the current working directory, as an absolute path.

    Return the current working directory, as an absolute path.

    returns

    the current working directory

  45. def relativePath(from: File, to: File): String

    Calculate the relative path between two files.

    Calculate the relative path between two files.

    from

    the starting file

    to

    the file to be converted to a relative path

    returns

    the (String) relative path

  46. def splitDrivePath(path: String): (String, String)

    Split a Windows-style path into drive name and path portions.

    Split a Windows-style path into drive name and path portions.

    path

    the path

    returns

    a (drive, path) tuple, either component of which can be * an empty string

  47. def splitPath(path: String, fileSep: String = fileSeparator): List[String]

    Split a path into its constituent components.

    Split a path into its constituent components. If the path is absolute, the first piece will have a file separator in the beginning. Examples:

    Input Output
    "" List("")
    "/" List("/")
    "foo" List("foo")
    "foo/bar" List("foo", "bar")
    "." List(".")
    "../foo" List("..", "foo")
    "./foo" List(".", "foo")
    "/foo/bar/baz" List("/foo", "bar", "baz")
    "foo/bar/baz" List("foo", "bar", "baz")
    "/foo" List("/foo")

    path

    the path

    fileSep

    the file separator to use. Defaults to the value of the "file.separator" property.

    returns

    the component pieces.

  48. final def synchronized[T0](arg0: ⇒ T0): T0

    Definition Classes
    AnyRef
  49. def temporaryDirectory: File

    Determine the temporary directory to use.

    Determine the temporary directory to use.

    returns

    the temporary directory

  50. def toString(): String

    Definition Classes
    AnyRef → Any
  51. def touch(path: String, time: Long = 1): Try[Boolean]

    Similar to the Unix touch command, this function:

    Similar to the Unix touch command, this function:

    • updates the access and modification times for a file
    • creates the file if it does not exist

    If the file is a directory, this method will return an error.

    path

    The file to touch

    time

    Set the last-modified time to this time, or to the current time if this parameter is negative.

    returns

    Failure(exception) on error, Success(true) on success

  52. def touchMany(files: Iterable[String], time: Long = 1): Try[Int]

    Similar to the Unix touch command, this function:

    Similar to the Unix touch command, this function:

    • updates the access and modification times for any existing files in a list of files
    • creates an nonexistent files in the list

    If any file in the list is a directory, this method will return an error.

    files

    Iterable of files to touch

    time

    Set the last-modified time to this time, or to the current time if this parameter is negative.

    returns

    Failure(exception) on error. Success(total) on success.

  53. def universalPath(path: String): String

    Converts a path name from its operating system-specific format to a universal path notation.

    Converts a path name from its operating system-specific format to a universal path notation. Universal path notation always uses a Unix-style "/" to separate path elements. A universal path can be converted to a native (operating system-specific) path via the native_path() function. Note that on POSIX-compliant systems, this function simply returns the path parameter unmodified.

    path

    the path to convert to universal path notation

    returns

    the universal path

  54. final def wait(): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  55. final def wait(arg0: Long, arg1: Int): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  56. final def wait(arg0: Long): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  57. def walk(top: String, topdown: Boolean = true): List[(String, List[String], List[String])]

    Directory tree generator, adapted from Python's os.walk() function.

    Directory tree generator, adapted from Python's os.walk() function.

    For each directory in the directory tree rooted at top (including top itself, but excluding '.' and '..'), yields a 3-tuple

    (dirpath, dirnames, filenames)

    dirpath is a string, the path to the directory. dirnames is a list of the names of the subdirectories in dirpath (excluding '.' and '..'). filenames is a list of the names of the non-directory files in dirpath. Note that the names in the lists are just names, with no path components. To get a full path (which begins with top) to a file or directory in dirpath, use dirpath + java.io.fileSeparator + name, or use joinPath().

    If topdown is true, the triple for a directory is generated before the triples for any of its subdirectories (directories are generated top down). If topdown is false, the triple for a directory is generated after the triples for all of its subdirectories (directories are generated bottom up).

    WARNING! This method does not grok symbolic links!

    top

    name of starting directory

    topdown

    true to do a top-down traversal, false otherwise.

    returns

    List of triplets, as described above.

  58. def withTemporaryDirectory[T](prefix: String)(action: (File) ⇒ T): T

    Allow execution of a block of code within the context of a temporary directory.

    Allow execution of a block of code within the context of a temporary directory. The temporary directory is cleaned up after the operation completes.

    prefix

    file name prefix to use

    action

    action to perform

    returns

    whatever the action returns

Inherited from AnyRef

Inherited from Any

Ungrouped