ocean.io.Path

A more direct route to the file-system than FilePath. Use this if you don't need path editing features. For example, if all you want is to check some path exists, using this module would likely be more convenient than FilePath:

if (exists ("some/file/path"))
    ...

These functions may be less efficient than FilePath because they generally attach a null to the filename for each underlying O/S call. Use Path when you need pedestrian access to the file-system, and are not manipulating the path components. Use FilePath where path-editing or mutation is desired.

We encourage the use of "named import" with this module, such as:

import Path = ocean.io.Path;

if (Path.exists ("some/file/path"))
    ...

Also residing here is a lightweight path-parser, which splits a filepath into constituent components. FilePath is based upon the same PathParser:

auto p = Path.parse ("some/file/path");
auto path = p.path;
auto name = p.name;
auto suffix = p.suffix;
...

Path normalization and pattern-matching is also hosted here via the normalize() and pattern() functions. See the doc towards the end of this module.

Members

Classes

IOException (from ocean.core.ExceptionDefinitions)
class IOException via public import ocean.core.ExceptionDefinitions : IOException, IllegalArgumentException;

The basic exception thrown by the ocean.io package. One should try to ensure that all Tango exceptions related to IO are derived from this one.

IllegalArgumentException (from ocean.core.ExceptionDefinitions)
class IllegalArgumentException via public import ocean.core.ExceptionDefinitions : IOException, IllegalArgumentException;

Thrown when an illegal argument is encountered.

Functions

accessed
Time accessed(cstring name)

Returns the time of the last access. Accurate to whatever the F/S supports, and in a format dictated by the file-system. For example NTFS keeps UTC time, while FAT timestamps are based on the local time.

children
FS.Listing children(cstring path, bool all)

Provides foreach support via a fruct, as in

collate
mstring[] collate(cstring path, cstring pattern, bool recurse)

Collate all files and folders from the given path whose name matches the given pattern. Folders will be traversed where recurse is enabled, and a set of matching names is returned as filepaths (including those folders which match the pattern.)

copy
void copy(cstring src, cstring dst)

Transfer the content of one file to another. Throws an IOException upon failure.

createFile
void createFile(cstring name)

Create a new file.

createFolder
void createFolder(cstring name)

Create a new directory.

createPath
void createPath(cstring path)

Create an entire path consisting of this folder along with all parent folders. The path should not contain '.' or '..' segments, which can be removed via the normalize() function.

created
Time created(cstring name)

Returns the time of file creation. Accurate to whatever the F/S supports, and in a format dictated by the file-system. For example NTFS keeps UTC time, while FAT timestamps are based on the local time.

exists
bool exists(cstring name)

Does this path currently exist?

fileSize
ulong fileSize(cstring name)

Return the file length (in bytes.)

isFile
bool isFile(cstring name)

Is this file actually a normal file? Not a directory or (on unix) a device file or link.

isFolder
bool isFolder(cstring name)

Is this file actually a folder/directory?

isReadable
bool isReadable(cstring name)
isWritable
bool isWritable(cstring name)

Is this file writable?

join
mstring join(const(char[])[] paths)

Join a set of path specs together. A path separator is potentially inserted between each of the segments.

main
void main()
modified
Time modified(cstring name)

Returns the time of the last modification. Accurate to whatever the F/S supports, and in a format dictated by the file-system. For example NTFS keeps UTC time, while FAT timestamps are based on the local time.

native
mstring native(mstring path)

Convert to native O/S path separators where that is required, such as when dealing with the Windows command-line.

normalize
mstring normalize(cstring in_path, mstring buf)

Normalizes a path component.

  • . segments are removed
  • <segment>/.. are removed
parent
cstring parent(cstring path)

Returns a path representing the parent of this one, with a special case concerning a trailing '/':

  • normal: /x/y/z => /x/y
  • normal: /x/y/ => /x/y
  • special: /x/y/ => /x
  • normal: /x => /
  • normal: / => empty
parse
PathParser parse(mstring path)

Parse a path into its constituent components.

patternMatch
bool patternMatch(cstring filename, cstring pattern)

Matches a pattern against a filename.

pop
cstring pop(cstring path)

Returns a path representing the parent of this one:

  • normal: /x/y/z => /x/y
  • normal: /x/y/ => /x/y
  • normal: /x => /
  • normal: / => empty
remove
bool remove(cstring name)

Remove the file/directory from the file-system. Returns true if successful, false otherwise.

remove
cstring[] remove(const(char[])[] paths)

Remove the files and folders listed in the provided paths. Where folders are listed, they should be preceded by their contained files in order to be successfully removed. Returns a set of paths that failed to be removed (where .length is zero upon success).

rename
void rename(cstring src, cstring dst)

Change the name or location of a file/directory.

replace
mstring replace(mstring path, char from, char to)

Replace all path 'from' instances with 'to', in place (overwrites the provided path).

split
mstring split(mstring path, mstring head, mstring tail)

Break a path into "head" and "tail" components. For example:

  • "/a/b/c" -> "/a","b/c"
  • "a/b/c" -> "a","b/c"
standard
mstring standard(mstring path)

Convert path separators to a standard format, using '/' as the path separator. This is compatible with Uri and all of the contemporary O/S which Tango supports. Known exceptions include the Windows command-line processor, which considers '/' characters to be switches instead. Use the native() method to support that.

timeStamps
FS.Stamps timeStamps(cstring name)

Return timestamp information.

timeStamps
void timeStamps(cstring name, Time accessed, Time modified)

Set the accessed and modified timestamps of the specified file.

Structs

FS
struct FS

Wraps the O/S specific calls with a D API. Note that these accept null-terminated strings only, which is why it's not public. We need this declared first to avoid forward-reference issues.

PathParser
struct PathParser

Parses a file path.

Time (from ocean.time.Time)
struct Time via public import ocean.time.Time : Time, TimeSpan;

Represents a point in time.

TimeSpan (from ocean.time.Time)
struct TimeSpan via public import ocean.time.Time : Time, TimeSpan;

This struct represents a length of time. The underlying representation is in units of 100ns. This allows the length of time to span to roughly +/- 10000 years.

Meta

License

Tango Dual License: 3-Clause BSD License / Academic Free License v3.0. See LICENSE_TANGO.txt for details.

Version

Mar 2008: Initial version
Oct 2009: Added PathUtil code