ファイルシステムにアクセスするためのモジュールです。Linux, macOS, iOS, FreeBSD, NetBSD, Windowsで動作します。
MAX_PATH_BYTES: パスとして利用できるバイト数の上限です。read: FileのInStreamインタフェースです。write: FileのOutStreamインタフェースです。File構造体は、io.InStream(File.ReadError)とio.OutStream(File.WriteError)とを実装しているため、io.read(File.ReadError)とio.write(File.WriteError)とを利用することができます。
read / writeで利用できるメソッドは、9章 ioを参照して下さい。
ディレクトリを操作するための構造体です。
std.fs に定義されている関数 cwd を呼び出すことでカレントワーキングディレクトリの Dir 構造体インスタンスを作成することができます。
cwd() Dir: カレントワーキングディレクトリの Dir インスタンスを作成します。Dir 構造体は次のメソッドを提供します。
openDir(sub_path: []u8, args: OpenDirOptions) OpenError!Dir: sub_path のディレクトリを開き、新しく Dir のインスタンスを作成します。close() void: ディレクトリを閉じます。access(sub_path: []u8, flags: File.OpenFlags) AccessError!void: sub_path が存在するかどうかテストします。openFile(sub_path: []u8, flags: File.OpenFlags) File.OpenError!File: sub_path のファイルを開き File インスタンスを返します。ファイルが存在しない場合はエラーとなります。createFile(sub_path: []u8, flags: File.CreateFlags) File.OpenError!File: sub_path のファイルを書き込みモードで開き File インスタンスを返します。ファイルが存在しない場合は作成します。readFileAlloc(allocator: heap.Allocator, file_path: []u8, max_bytes: usize) ![]mut u8: allocatorで確保したメモリに、file_pathのファイルを読み込んだ結果を返します。writeFile(sub_path: []u8, data: []u8) !void: sub_pathのファイルを開き、dataを書き込みます。copyFile(source_dir: Dir, source_path: []u8, dest_dir: Dir, dest_path: []u8, options: CopyFileOptions) !void: source_pathのファイルをdest_pathにコピーします。makePath(sub_path: []u8) !void: 再帰的にディレクトリを作成します。makeDir(sub_path: []u8) !void: sub_path に指定したディレクトリを作成します。deleteDir(sub_path: []u8) DeleteDirError!void: sub_path に指定したディレクトリを削除します。readLink(sub_path: []u8, buffer: *mut [MAX_PATH_BYTES]u8) ![]mut u8 : sub_path に指定したシンボリックリンクのパスを取得します。OpenFlags 構造体は、ファイルを開く際の読み込み、書き込みのモードを指定します。初期値は読み込み専用となります。
pub const OpenFlags = struct {
read: bool = true,
write: bool = false,
};
CreateFlags 構造体は、以下のように作成するファイルの属性を指定する構造体です。
pub const CreateFlags = struct {
/// Whether the file will be created with read access.
read: bool = false,
/// If the file already exists, and is a regular file, and the access
/// mode allows writing, it will be truncated to length 0.
truncate: bool = true,
/// Ensures that this open call creates the file, otherwise causes
/// `error.FileAlreadyExists` to be returned.
exclusive: bool = false,
/// For POSIX systems this is the file system mode the file will
/// be created with.
mode: Mode = default_mode,
};
ファイルを操作するための構造体です。
File 構造体は次のメソッドを提供します。
close() void: ファイルをクローズします。seekBy(offset: i64) SeekError!void: ファイルオフセットを現在のオフセット位置からoffset分移動します。seekFromEnd(offset: i64) SeekError!void: ファイルオフセットをファイルの終了位置からoffset分移動します。seekTo(offset: u64) SeekError!void: ファイルオフセットをファイルの先頭からoffset分移動します。read(buffer: []mut u8) ReadError![]mut u8: ファイルからデータをbufferに読み込みます。write(bytes: []u8) WriteError![]u8: ファイルにbytesのデータを書き込みます。copyFileAbsolute(source_path: []u8, dest_path: []u8, args: CopyFileOptions) !void: 絶対パスを指定して source_pathのファイルをdest_pathにコピーします。walkPath(allocator: heap.Allocator, dir_path: []u8) !Walker: dir_pathからディレクトリを順番に辿るWalkerを作成します。selfExePathAlloc(allocator: heap.Allocator) ![]mut u8: 現在実行しているバイナリのパスを取得します。selfExeDirPath(out_buffer: *mut [MAX_PATH_BYTES]u8) SelfExePathError![]u8: 現在実行しているバイナリが置かれているディレクトリを取得します。getStdIn() GetStdIoError!File: 標準入力ファイルを取得します。getStdOut() GetStdIoError!File: 標準出力ファイルを取得します。getStdErr() GetStdIoError!File: 標準エラーファイルを取得します。OSのファイルシステムのパスを操作するための定数と関数です。
const sep_windows = '\\';const sep_posix = '/';const sep = if (builtin.os.tag == .windows) sep_windows else sep_posix;join(allocator: heap.Allocator, paths: [][]u8) ![]mut u8: pathsに格納された複数のパスを、ターゲットプラットフォームのセパレータを使って連結します。isAbsolute(path: []u8) bool: pathが絶対パスであればtrueを、そうでなければfalseを返します。basename(path: []u8) []u8: pathからディレクトリパスを取り除いたファイル名を取得します。
☰ 人の生きた証は永遠に残るよう ☰
Copyright © 2018-2020 connectFree Corporation. All rights reserved. | 特定商取引法に基づく表示
Zen, the Zen three-circles logo and The Zen Programming Language are trademarks of connectFree corporation in Japan and other countries.