Module std::old_io::fsUnstable [-] [+] [src]

Synchronous File I/O

This module provides a set of functions and traits for working with regular files & directories on a filesystem.

At the top-level of the module are a set of freestanding functions, associated with various filesystem operations. They all operate on Path objects.

All operations in this module, including those as part of File et al block the task during execution. In the event of failure, all functions/methods will return an IoResult type with an Err value.

Also included in this module is an implementation block on the Path object defined in std::path::Path. The impl adds useful methods about inspecting the metadata of a file. This includes getting the stat information, reading off particular bits of it, etc.

Example

fn main() { #![allow(unused_must_use)] use std::old_io::fs::PathExtensions; use std::old_io::{File, fs}; let path = Path::new("foo.txt"); // create the file, whether it exists or not let mut file = File::create(&path); file.write(b"foobar"); drop(file); // open the file in read-only mode let mut file = File::open(&path); file.read_to_end(); println!("{}", path.stat().unwrap().size); drop(file); fs::unlink(&path); }
use std::old_io::fs::PathExtensions;
use std::old_io::{File, fs};

let path = Path::new("foo.txt");

// create the file, whether it exists or not
let mut file = File::create(&path);
file.write(b"foobar");

// open the file in read-only mode
let mut file = File::open(&path);
file.read_to_end();

println!("{}", path.stat().unwrap().size);
fs::unlink(&path);

Structs

Directories

An iterator that walks over a directory

File

Unconstrained file access type that exposes read and write operations

Traits

PathExtensions

Utility methods for paths.

Functions

change_file_times

Changes the timestamps for a file's last modification and access time. The file at the path specified will have its last access time set to atime and its modification time set to mtime. The times specified should be in milliseconds.

chmod

Changes the permission mode bits found on a file or a directory. This function takes a mask from the io module

chown

Change the user and group owners of a file at the specified path.

copy

Copies the contents of one file to another. This function will also copy the permission bits of the original file to the destination file.

link

Creates a new hard link on the filesystem. The dst path will be a link pointing to the src path. Note that systems often require these two paths to both be located on the same filesystem.

lstat

Perform the same operation as the stat function, except that this function does not traverse through symlinks. This will return information about the symlink file instead of the file that it points to.

mkdir

Create a new, empty directory at the provided path

mkdir_recursive

Recursively create a directory and all of its parent components if they are missing.

readdir

Retrieve a vector containing all entries within a provided directory

readlink

Reads a symlink, returning the file that the symlink points to.

rename

Rename a file or directory to a new name.

rmdir

Remove an existing, empty directory

rmdir_recursive

Removes a directory at this path, after removing all its contents. Use carefully!

stat

Given a path, query the file system to get information about a file, directory, etc. This function will traverse symlinks to query information about the destination file.

symlink

Creates a new symbolic link on the filesystem. The dst path will be a symlink pointing to the src path.

unlink

Unlink a file from the underlying filesystem.

walk_dir

Returns an iterator that will recursively walk the directory structure rooted at path. The path given will not be iterated over, and this will perform iteration in some top-down order. The contents of unreadable subdirectories are ignored.