tango.io.Path

Members

Classes

IOException (from tango.core.Exception)
class IOException via public import tango.core.Exception : IOException, IllegalArgumentException;

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

IllegalArgumentException (from tango.core.Exception)
class IllegalArgumentException via public import tango.core.Exception : IOException, IllegalArgumentException;

Thrown when an illegal argument is encountered.

Functions

accessed
Time accessed(const(char)[] 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(const(char)[] path, bool all)

Provides foreach support via a fruct, as in

collate
char[][] collate(const(char)[] path, const(char)[] 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(const(char)[] src, const(char)[] dst)

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

createFile
void createFile(const(char)[] name)

Create a new file.

createFolder
void createFolder(const(char)[] name)

Create a new directory.

createPath
void createPath(const(char)[] 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(const(char)[] 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(const(char)[] name)

Does this path currently exist?

fileSize
ulong fileSize(const(char)[] name)

Return the file length (in bytes.)

isFile
bool isFile(const(char)[] name)

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

isFolder
bool isFolder(const(char)[] name)

Is this file actually a folder/directory?

isWritable
bool isWritable(const(char)[] name)

Is this file writable?

join
char[] 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(const(char)[] 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
char[] native(char[] path)

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

normalize
char[] normalize(const(char)[] in_path, char[] buf)

Normalizes a path component.

  • . segments are removed
  • <segment>/.. are removed
parent
inout(char)[] parent(inout(char)[] 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!(char_t) parse(char_t[] path)

Parse a path into its constituent components.

patternMatch
bool patternMatch(const(char)[] filename, const(char)[] pattern)

Matches a pattern against a filename.

pop
inout(char)[] pop(inout(char)[] 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(const(char)[] name)

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

remove
char[][] remove(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(const(char)[] src, const(char)[] dst)

Change the name or location of a file/directory.

replace
char[] replace(char[] path, char from, char to)

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

split
inout(char)[] split(inout(char)[] path, inout(char)[] head, inout(char)[] tail)

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

  • "/a/b/c" -> "/a","b/c"
  • "a/b/c" -> "a","b/c"
standard
char[] standard(char[] 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(const(char)[] name)

Return timestamp information.

timeStamps
void timeStamps(const(char)[] 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(char_t = char)

Parses a file path.

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

Represents a point in time.

TimeSpan (from tango.time.Time)
struct TimeSpan via public import tango.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

BSD style: $(LICENSE)

Version

Mar 2008: Initial version
Oct 2009: Added PathUtil code

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 = tango.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.

Compile with -version=Win32SansUnicode to enable Win95 & Win32s file support.