std.file
Variables
useWfuncs
:
int
Functions
void
append
(
char
[]
name
,
void
[]
buffer
)
Append buffer[] to file name[].
Throws:
FileException on error.
void
chdir
(
char
[]
pathname
)
Change directory to pathname[].
Throws:
FileException on error.
void
copy
(
char
[]
from
,
char
[]
to
)
Copy a file from[] to[].
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.
char
[]
getcwd
()
Get current directory.
Throws:
FileException on error.
ulong
getSize
(
char
[]
name
)
Get size of file name[].
Throws:
FileException on error.
void
getTimes
(
char
[]
name
,
long
ftc
,
long
fta
,
long
ftm
)
Get creation/access/modified times of file name[].
Throws:
FileException on error.
int
isdir
(
char
[]
name
)
Is name[] a directory?
Throws:
FileException if name[] doesn't exist.
int
isfile
(
char
[]
name
)
Is name[] a file?
Throws:
FileException if name[] doesn't exist.
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
(
string
[
]
args
)
{
auto
dirs
=
std
.
file
.
listdir
(
args
[
1
]
)
;
foreach
(
d
;
dirs
)
writefln
(
d
)
;
}
void
mkdir
(
char
[]
pathname
)
Make directory pathname[].
Throws:
FileException on error.
void
[]
read
(
char
[]
name
)
Read file name[], return array of bytes read.
Throws:
FileException on error.
void
remove
(
char
[]
name
)
Delete file name[].
Throws:
FileException on error.
void
rename
(
char
[]
from
,
char
[]
to
)
Rename file from[] to to[].
Throws:
FileException on error.
void
rmdir
(
char
[]
pathname
)
Remove directory pathname[].
Throws:
FileException on error.
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
write
(
char
[]
name
,
void
[]
buffer
)
Write buffer[] to file name[].
Throws:
FileException on error.
Structs
DirEntry
Directory Entry
Fields
attributes
:
uint
creationTime
:
long
lastAccessTime
:
long
lastWriteTime
:
long
name
:
char
[]
size
:
ulong
Methods
void
init
(
char
[]
path
,
WIN32_FIND_DATA
*
fd
)
uint
isdir
()
Return !=0 if DirEntry is a directory.
uint
isfile
()
Return !=0 if DirEntry is a file.
Classes
FileException
:
Exception
Exception thrown for file I/O errors.
Super hierarchy:
Object
->
Exception
->
FileException
Fields
errno
:
uint
Constructors
this
(
char
[]
name
)
Inherited methods
from
Object
:
factory
,
notifyRegister
,
notifyUnRegister
,
opCmp
,
opEquals
,
print
,
toHash
,
toString
from
Exception
:
print
,
toString