9. Directories


Getting and Setting Timestamps

(reatime, writetime) = File::stat(filename){Readtime, Writetime}
# modify readtime, writetime
filename.File::utime(readtime, writetime)

Deleting a File


Copying or Moving a File

File::copy(oldfile, newfile)
File::rename(oldfile, newfile)
File::move(oldfile, newfile)

Recognizing Two Names for the Same File

seen = {}
files.each(f ->
    seen{File::stat(f){Device, Inode}}.push!(f)
seen.to_list.sort.each((dev,ino), l ->
    if l.size > 1 then
        # l is a list of filenames for the same file

Processing All Files in a Directory

Dir::open(dirname, Absolute).each(file ->
    # do something with "{file}"

Globbing, or Getting a List of Filenames Matching a Pattern

list = Dir::glob("*.c")

Processing All Files in a Directory Recursively

dirlist.each(dir ->
    Dir::open(dir, Recursive | Absolute | Depth_only).each(f ->

Removing a Directory and Its Contents

Sys::args.each(dir ->
    Dir::open(dir, Recursive | Absolute | Depth_first).each(File::delete)

Renaming Files

names.each(file ->
    newname = compute_newname(file)
    File::rename(file, newname) or warn("Couldn't rename {file} to {newname}: {Sys::errno_string}\n")

Splitting a Filename into Its Component Parts


Program: symirror

Program: lst