► |  | How to Design Programs Teachpacks

1 | Ht DP Teachpacks
2 | Ht DP/ 2e Teachpacks

▼ | 1 | Ht DP Teachpacks

1.1 | Manipulating Images: "image.rkt"
1.2 | Simulations and Animations: "world.rkt"
1.3 | Converting Temperatures: "convert.rkt"
1.4 | Guessing Numbers: "guess.rkt"
1.5 | Master Minding: "master.rkt"
1.6 | Playing Master Mind: "master-play.rkt"
1.7 | Simple Drawing: "draw.rkt"
1.8 | Hangman: "hangman.rkt"
1.9 | Playing Hangman: "hangman-play.rkt"
1.10 | Managing Control Arrows: "arrow.rkt"
1.11 | Manipulating Simple HTML Documents: "docs.rkt"
1.12 | Working with Files and Directories: "dir.rkt"
1.13 | Graphing Functions: "graphing.rkt"
1.14 | Simple Graphical User Interfaces: "gui.rkt"
1.15 | An Arrow GUI: "arrow-gui.rkt"
1.16 | Controlling an Elevator: "elevator.rkt"
1.17 | Lookup GUI: "lkup-gui.rkt"
1.18 | Guess GUI: "guess-gui.rkt"
1.19 | Queens: "show-queen.rkt"
1.20 | Matrix Functions: "matrix.rkt"

On this page:

dir
file
create-dir

top ← prev up next →

#### 1.12`` Working with Files and Directories: "dir.rkt"

(require htdp/dir)

The teachpack provides structures and functions for working with files and directories:

> > struct

> > (struct |  | dir (name dirs files)
> > |  | #:extra-constructor-name make-dir)

> name : symbol?
> dirs : (listof dir?)
> files : (listof file?)

> > struct

> > (struct |  | file (name size content)
> > |  | #:extra-constructor-name make-file)

> name : symbol?
> size : integer?
> content : (listof char?)

> > procedure

> > (create-dir path) → dir?

> path : symbol?

Turns the directory found at path on your computer into an instance of dir?.

Sample: Set teachpack to "dir.rkt" and click Run:

> > (create-dir ".")
> (make-dir
> '|.|
> empty
> (cons (make-file 'ball1.gif 1289 empty)
> (cons (make-file 'blueball.gif 205 empty)
> (cons (make-file 'greenbal.gif 204 empty)
> (cons (make-file 'redball.gif 203 empty)
> (cons (make-file 'ufo.gif 1044 empty)
> (cons (make-file 'gif-test.rkt 5811 empty)
> empty)))))))

Using “.” usually means the directory in which your program is located. In this case, the directory contains no sub-directories and six files.

Note: Soft links are always treated as if they were empty files.

top ← prev up next →