D
Language
Phobos
Comparisons
object
std
std.base64
std.boxer
std.compiler
std.conv
std.cover
std.ctype
std.date
std.demangle
std.file
std.format
std.gc
std.intrinsic
std.math
std.md5
std.mmfile
std.openrj
std.outbuffer
std.path
std.process
std.random
std.recls
std.regexp
std.socket
std.socketstream
std.stdint
std.stdio
std.cstream
std.stream
std.string
std.system
std.thread
std.uri
std.utf
std.zip
std.zlib
std.c.fenv
std.c.math
std.c.process
std.c.stdarg
std.c.stddef
std.c.stdio
std.c.stdlib
std.c.string
std.c.time
std.c.wcharh
std.windows.charset
std.windows
std.linux
std.c.windows
std.c.linux
|
std.file
- class FileException: object.Exception;
- Exception thrown for file I/O errors.
- void[] read(char[] name);
- Read file name[], return array of bytes read.
Throws:
FileException on error.
- void write(char[] name, void[] buffer);
- Write buffer[] to file name[].
Throws:
FileException on error.
- void append(char[] name, void[] buffer);
- Append buffer[] to file name[].
Throws:
FileException on error.
- void rename(char[] from, char[] to);
- Rename file from[] to to[].
Throws:
FileException on error.
- void remove(char[] name);
- Delete file name[].
Throws:
FileException on error.
- ulong getSize(char[] name);
- Get size of file name[].
Throws:
FileException on error.
- int exists(char[] name);
- Does file name[] (or directory) exist?
Return 1 if it does, 0 if not.
- uint getAttributes(char[] name);
- Get file name[] attributes.
Throws:
FileException on error.
- int isfile(char[] name);
- Is name[] a file?
Throws:
FileException if name[] doesn't exist.
- int isdir(char[] name);
- Is name[] a directory?
Throws:
FileException if name[] doesn't exist.
- void chdir(char[] pathname);
- Change directory to pathname[].
Throws:
FileException on error.
- void mkdir(char[] pathname);
- Make directory pathname[].
Throws:
FileException on error.
- void rmdir(char[] pathname);
- Remove directory pathname[].
Throws:
FileException on error.
- char[] getcwd();
- Get current directory.
Throws:
FileException on error.
- struct DirEntry;
- Directory Entry
- char[] name;
- file or directory name
- ulong size;
- size of file in bytes
- long creationTime;
- time of file creation
- long lastAccessTime;
- time file was last accessed
- long lastWriteTime;
- time file was last written to
- int isdir();
- Return !=0 if DirEntry is a directory.
- int isfile();
- Return !=0 if DirEntry is a file.
- char[][] listdir(char[] pathname);
- Return contents of directory pathname[].
The names in the contents do not include the pathname.
Throws:
FileException on error
Example:
This program lists all the files and subdirectories in its
path argument.
import std.stdio;
import std.file;
void main(char[][] args)
{
char[][] dirs = std.file.listdir(args[1]);
foreach (char[] d; dirs)
writefln(d);
}
- char[][] listdir(char[] pathname, char[] pattern);
char[][] listdir(char[] pathname, RegExp r);
- Return all the files in the directory and its subdirectories
that match pattern or regular expression r.
Params:
char[] pathname |
Directory name |
char[] pattern |
String with wildcards, such as "*.d". The supported
wildcard strings are described under fnmatch() in
std.path. |
r |
Regular expression, for more powerful pattern matching. |
Example:
This program lists all the files with a "d" extension in
the path passed as the first argument.
import std.stdio;
import std.file;
void main(char[][] args)
{
char[][] d_source_files = std.file.listdir(args[1], "*.d");
foreach (char[] d; d_source_files)
writefln(d);
}
A regular expression version that searches for all files with "d" or
"obj" extensions:
import std.stdio;
import std.file;
import std.regexp;
void main(char[][] args)
{
char[][] d_source_files = std.file.listdir(args[1], RegExp(r"\.(d|obj)$"));
foreach (char[] d; d_source_files)
writefln(d);
}
- void listdir(char[] pathname, bool delegate(char[] filename) callback);
- For each file and directory name in pathname[],
pass it to the callback delegate.
Params:
bool delegate(char[] filename) callback |
Delegate that processes each
filename in turn. Returns true to
continue, false to stop. |
Example:
This program lists all the files in its
path argument, including the path.
import std.stdio;
import std.path;
import std.file;
void main(char[][] args)
{
char[] pathname = args[1];
char[][] result;
bool listing(char[] filename)
{
result ~= std.path.join(pathname, filename);
return true; // continue
}
listdir(pathname, &listing);
foreach (char[] name; result)
writefln("%s", name);
}
- void listdir(char[] pathname, bool delegate(DirEntry * de) callback);
- For each file and directory DirEntry in pathname[],
pass it to the callback delegate.
Params:
bool delegate(DirEntry * de) callback |
Delegate that processes each
DirEntry in turn. Returns true to
continue, false to stop. |
Example:
This program lists all the files in its
path argument and all subdirectories thereof.
import std.stdio;
import std.file;
void main(char[][] args)
{
bool callback(DirEntry* de)
{
if (de.isdir)
listdir(de.name, &callback);
else
writefln(de.name);
return true;
}
listdir(args[1], &callback);
}
- char* toMBSz(char[] s);
- Since Win 9x does not support the "W" API's, first convert
to wchar, then convert to multibyte using the current code
page.
(Thanks to yaneurao for this)
Deprecated:
use std.windows.charset.toMBSz instead.
- void copy(char[] from, char[] to);
- Copy a file from[] to[].
|