]> gitweb.factorcode.org Git - factor.git/blob - basis/io/directories/directories-docs.factor
Merge branch 'master' of git://factorcode.org/git/factor
[factor.git] / basis / io / directories / directories-docs.factor
1 USING: help.markup help.syntax io.files.private io.pathnames
2 quotations ;
3 IN: io.directories
4
5 HELP: cwd
6 { $values { "path" "a pathname string" } }
7 { $description "Outputs the current working directory of the Factor process." }
8 { $errors "Windows CE has no concept of ``current directory'', so this word throws an error there." }
9 { $notes "User code should use " { $link with-directory } " or " { $link set-current-directory } " instead." } ;
10
11 HELP: cd
12 { $values { "path" "a pathname string" } }
13 { $description "Changes the current working directory of the Factor process." }
14 { $errors "Windows CE has no concept of ``current directory'', so this word throws an error there." }
15 { $notes "User code should use " { $link with-directory } " or " { $link set-current-directory } " instead." } ;
16
17 { cd cwd current-directory set-current-directory with-directory } related-words
18
19 HELP: current-directory
20 { $description "A variable holding the current directory as an absolute path. Words that use the filesystem do so in relation to this variable."
21 $nl
22 "This variable should never be set directly; instead, use " { $link set-current-directory } " or " { $link with-directory } ". This preserves the invariant that the value of this variable is an absolute path." } ;
23
24 HELP: set-current-directory
25 { $values { "path" "a pathname string" } }
26 { $description "Changes the " { $link current-directory } " variable."
27 $nl
28 "If " { $snippet "path" } " is relative, it is first resolved relative to the current directory. If " { $snippet "path" } " is absolute, it becomes the new current directory." } ;
29
30 HELP: with-directory
31 { $values { "path" "a pathname string" } { "quot" quotation } }
32 { $description "Calls the quotation in a new dynamic scope with the " { $link current-directory } " variable rebound."
33 $nl
34 "If " { $snippet "path" } " is relative, it is first resolved relative to the current directory. If " { $snippet "path" } " is absolute, it becomes the new current directory." } ;
35
36 HELP: (directory-entries)
37 { $values { "path" "a pathname string" } { "seq" "a sequence of " { $snippet "{ name dir? }" } " pairs" } }
38 { $description "Outputs the contents of a directory named by " { $snippet "path" } "." }
39 { $notes "This is a low-level word, and user code should call one of the related words instead." } ;
40
41 HELP: directory-entries
42 { $values { "path" "a pathname string" } { "seq" "a sequence of " { $link directory-entry } " objects" } }
43 { $description "Outputs the contents of a directory named by " { $snippet "path" } "." } ;
44
45 HELP: directory-files
46 { $values { "path" "a pathname string" } { "seq" "a sequence of filenames" } }
47 { $description "Outputs the contents of a directory named by " { $snippet "path" } "." } ;
48
49 HELP: with-directory-files
50 { $values { "path" "a pathname string" } { "quot" quotation } }
51 { $description "Calls the quotation with the directory file names on the stack and with the directory set as the " { $link current-directory } ".  Restores the current directory after the quotation is called." } ;
52
53 HELP: delete-file
54 { $values { "path" "a pathname string" } }
55 { $description "Deletes a file." }
56 { $errors "Throws an error if the file could not be deleted." } ;
57
58 HELP: make-directory
59 { $values { "path" "a pathname string" } }
60 { $description "Creates a directory." }
61 { $errors "Throws an error if the directory could not be created." } ;
62
63 HELP: make-directories
64 { $values { "path" "a pathname string" } }
65 { $description "Creates a directory and any parent directories which do not yet exist." }
66 { $errors "Throws an error if the directories could not be created." } ;
67
68 HELP: delete-directory
69 { $values { "path" "a pathname string" } }
70 { $description "Deletes a directory. The directory must be empty." }
71 { $errors "Throws an error if the directory could not be deleted." } ;
72
73 HELP: touch-file
74 { $values { "path" "a pathname string" } }
75 { $description "Updates the modification time of a file or directory. If the file does not exist, creates a new, empty file." }
76 { $errors "Throws an error if the file could not be touched." } ;
77
78 HELP: move-file
79 { $values { "from" "a pathname string" } { "to" "a pathname string" } }
80 { $description "Moves or renames a file." }
81 { $errors "Throws an error if the file does not exist or if the move operation fails." } ;
82
83 HELP: move-file-into
84 { $values { "from" "a pathname string" } { "to" "a directory pathname string" } }
85 { $description "Moves a file to another directory without renaming it." }
86 { $errors "Throws an error if the file does not exist or if the move operation fails." } ;
87
88 HELP: move-files-into
89 { $values { "files" "a sequence of pathname strings" } { "to" "a directory pathname string" } }
90 { $description "Moves a set of files to another directory." }
91 { $errors "Throws an error if the file does not exist or if the move operation fails." } ;
92
93 HELP: copy-file
94 { $values { "from" "a pathname string" } { "to" "a pathname string" } }
95 { $description "Copies a file." }
96 { $notes "This operation attempts to preserve the original file's attributes, however not all attributes may be preserved." }
97 { $errors "Throws an error if the file does not exist or if the copy operation fails." } ;
98
99 HELP: copy-file-into
100 { $values { "from" "a pathname string" } { "to" "a directory pathname string" } }
101 { $description "Copies a file to another directory." }
102 { $errors "Throws an error if the file does not exist or if the copy operation fails." } ;
103
104 HELP: copy-files-into
105 { $values { "files" "a sequence of pathname strings" } { "to" "a directory pathname string" } }
106 { $description "Copies a set of files to another directory." }
107 { $errors "Throws an error if the file does not exist or if the copy operation fails." } ;
108
109 ARTICLE: "current-directory" "Current working directory"
110 "File system I/O operations use the value of a variable to resolve relative pathnames:"
111 { $subsection current-directory }
112 "This variable can be changed with a pair of words:"
113 { $subsection set-current-directory }
114 { $subsection with-directory }
115 "This variable is independent of the operating system notion of ``current working directory''. While all Factor I/O operations use the variable and not the operating system's value, care must be taken when making FFI calls which expect a pathname. The first option is to resolve relative paths:"
116 { $subsection (normalize-path) }
117 "The second is to change the working directory of the current process:"
118 { $subsection cd }
119 { $subsection cwd } ;
120
121 ARTICLE: "io.directories.listing" "Directory listing"
122 "Directory listing:"
123 { $subsection directory-entries }
124 { $subsection directory-files }
125 { $subsection with-directory-files } ;
126
127 ARTICLE: "io.directories.create" "Creating directories"
128 { $subsection make-directory }
129 { $subsection make-directories } ;
130
131 ARTICLE: "delete-move-copy" "Deleting, moving, and copying files"
132 "Operations for deleting and copying files come in two forms:"
133 { $list
134     { "Words named " { $snippet { $emphasis "operation" } "-file" } " which work on regular files only." }
135     { "Words named " { $snippet { $emphasis "operation" } "-tree" } " works on directory trees recursively, and also accepts regular files." }
136 }
137 "The operations for moving and copying files come in three flavors:"
138 { $list
139     { "A word named " { $snippet { $emphasis "operation" } } " which takes a source and destination path." }
140     { "A word named " { $snippet { $emphasis "operation" } "-into" } " which takes a source path and destination directory. The destination file will be stored in the destination directory and will have the same file name as the source path." }
141     { "A word named " { $snippet { $emphasis "operation" } "s-into" } " which takes a sequence of source paths and destination directory." }
142 }
143 "Since both of the above lists apply to copying files, that this means that there are a total of six variations on copying a file."
144 $nl
145 "Deleting files:"
146 { $subsection delete-file }
147 { $subsection delete-directory }
148 "Moving files:"
149 { $subsection move-file }
150 { $subsection move-file-into }
151 { $subsection move-files-into }
152 "Copying files:"
153 { $subsection copy-file }
154 { $subsection copy-file-into }
155 { $subsection copy-files-into }
156 "On most operating systems, files can only be moved within the same file system. To move files between file systems, use " { $link copy-file } " followed by " { $link delete-file } " on the old name." ;
157
158 ARTICLE: "io.directories" "Directory manipulation"
159 "The " { $vocab-link "io.directories" } " vocabulary defines words for inspecting and manipulating directory trees."
160 { $subsection home }
161 { $subsection "current-directory" }
162 { $subsection "io.directories.listing" }
163 { $subsection "io.directories.create" }
164 { $subsection "delete-move-copy" } ;
165
166 ABOUT: "io.directories"