3
<title>Filesystem Utilities - Untitled</title>
4
<meta http-equiv="Content-Type" content="text/html">
5
<meta name="description" content="Untitled">
6
<meta name="generator" content="makeinfo 4.11">
7
<link title="Top" rel="start" href="index.html#Top">
8
<link rel="up" href="System-Utilities.html#System-Utilities" title="System Utilities">
9
<link rel="prev" href="Timing-Utilities.html#Timing-Utilities" title="Timing Utilities">
10
<link rel="next" href="File-Archiving-Utilities.html#File-Archiving-Utilities" title="File Archiving Utilities">
11
<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
12
<meta http-equiv="Content-Style-Type" content="text/css">
13
<style type="text/css"><!--
14
pre.display { font-family:inherit }
15
pre.format { font-family:inherit }
16
pre.smalldisplay { font-family:inherit; font-size:smaller }
17
pre.smallformat { font-family:inherit; font-size:smaller }
18
pre.smallexample { font-size:smaller }
19
pre.smalllisp { font-size:smaller }
20
span.sc { font-variant:small-caps }
21
span.roman { font-family:serif; font-weight:normal; }
22
span.sansserif { font-family:sans-serif; font-weight:normal; }
28
<a name="Filesystem-Utilities"></a>
29
Next: <a rel="next" accesskey="n" href="File-Archiving-Utilities.html#File-Archiving-Utilities">File Archiving Utilities</a>,
30
Previous: <a rel="previous" accesskey="p" href="Timing-Utilities.html#Timing-Utilities">Timing Utilities</a>,
31
Up: <a rel="up" accesskey="u" href="System-Utilities.html#System-Utilities">System Utilities</a>
35
<h3 class="section">35.2 Filesystem Utilities</h3>
37
<p>Octave includes the following functions for renaming and deleting files,
38
creating, deleting, and reading directories, and for getting information
39
about the status of files.
41
<p><a name="doc_002drename"></a>
44
— Built-in Function: [<var>err</var>, <var>msg</var>] = <b>rename</b> (<var>old, new</var>)<var><a name="index-rename-1973"></a></var><br>
45
<blockquote><p>Change the name of file <var>old</var> to <var>new</var>.
47
<p>If successful, <var>err</var> is 0 and <var>msg</var> is an empty string.
48
Otherwise, <var>err</var> is nonzero and <var>msg</var> contains a
49
system-dependent error message.
53
<strong>See also:</strong> ls, dir.
54
</p></blockquote></div>
56
<p><a name="doc_002dlink"></a>
59
— Built-in Function: [<var>err</var>, <var>msg</var>] = <b>link</b> (<var>old, new</var>)<var><a name="index-link-1974"></a></var><br>
60
<blockquote><p>Create a new link (also known as a hard link) to an existing file.
62
<p>If successful, <var>err</var> is 0 and <var>msg</var> is an empty string.
63
Otherwise, <var>err</var> is nonzero and <var>msg</var> contains a
64
system-dependent error message.
68
<strong>See also:</strong> symlink.
69
</p></blockquote></div>
71
<p><a name="doc_002dsymlink"></a>
74
— Built-in Function: [<var>err</var>, <var>msg</var>] = <b>symlink</b> (<var>old, new</var>)<var><a name="index-symlink-1975"></a></var><br>
75
<blockquote><p>Create a symbolic link <var>new</var> which contains the string <var>old</var>.
77
<p>If successful, <var>err</var> is 0 and <var>msg</var> is an empty string.
78
Otherwise, <var>err</var> is nonzero and <var>msg</var> contains a
79
system-dependent error message.
83
<strong>See also:</strong> link, readlink.
84
</p></blockquote></div>
86
<p><a name="doc_002dreadlink"></a>
89
— Built-in Function: [<var>result</var>, <var>err</var>, <var>msg</var>] = <b>readlink</b> (<var>symlink</var>)<var><a name="index-readlink-1976"></a></var><br>
90
<blockquote><p>Read the value of the symbolic link <var>symlink</var>.
92
<p>If successful, <var>result</var> contains the contents of the symbolic link
93
<var>symlink</var>, <var>err</var> is 0 and <var>msg</var> is an empty string.
94
Otherwise, <var>err</var> is nonzero and <var>msg</var> contains a
95
system-dependent error message.
99
<strong>See also:</strong> link, symlink.
100
</p></blockquote></div>
102
<p><a name="doc_002dunlink"></a>
105
— Built-in Function: [<var>err</var>, <var>msg</var>] = <b>unlink</b> (<var>file</var>)<var><a name="index-unlink-1977"></a></var><br>
106
<blockquote><p>Delete the file named <var>file</var>.
108
<p>If successful, <var>err</var> is 0 and <var>msg</var> is an empty string.
109
Otherwise, <var>err</var> is nonzero and <var>msg</var> contains a
110
system-dependent error message.
111
</p></blockquote></div>
113
<p><a name="doc_002dreaddir"></a>
116
— Built-in Function: [<var>files</var>, <var>err</var>, <var>msg</var>] = <b>readdir</b> (<var>dir</var>)<var><a name="index-readdir-1978"></a></var><br>
117
<blockquote><p>Return names of the files in the directory <var>dir</var> as a cell array of
118
strings. If an error occurs, return an empty cell array in <var>files</var>.
120
<p>If successful, <var>err</var> is 0 and <var>msg</var> is an empty string.
121
Otherwise, <var>err</var> is nonzero and <var>msg</var> contains a
122
system-dependent error message.
126
<strong>See also:</strong> dir, glob.
127
</p></blockquote></div>
129
<p><a name="doc_002dmkdir"></a>
132
— Built-in Function: [<var>status</var>, <var>msg</var>, <var>msgid</var>] = <b>mkdir</b> (<var>dir</var>)<var><a name="index-mkdir-1979"></a></var><br>
133
— Built-in Function: [<var>status</var>, <var>msg</var>, <var>msgid</var>] = <b>mkdir</b> (<var>parent, dir</var>)<var><a name="index-mkdir-1980"></a></var><br>
134
<blockquote><p>Create a directory named <var>dir</var>.
136
<p>If successful, <var>status</var> is 1, with <var>msg</var> and <var>msgid</var> empty
137
character strings. Otherwise, <var>status</var> is 0, <var>msg</var> contains a
138
system-dependent error message, and <var>msgid</var> contains a unique
143
<strong>See also:</strong> rmdir.
144
</p></blockquote></div>
146
<p><a name="doc_002drmdir"></a>
149
— Built-in Function: [<var>status</var>, <var>msg</var>, <var>msgid</var>] = <b>rmdir</b> (<var>dir</var>)<var><a name="index-rmdir-1981"></a></var><br>
150
— Built-in Function: [<var>status</var>, <var>msg</var>, <var>msgid</var>] = <b>rmdir</b> (<var>dir, </var><code>"s"</code>)<var><a name="index-rmdir-1982"></a></var><br>
151
<blockquote><p>Remove the directory named <var>dir</var>.
153
<p>If successful, <var>status</var> is 1, with <var>msg</var> and <var>msgid</var> empty
154
character strings. Otherwise, <var>status</var> is 0, <var>msg</var> contains a
155
system-dependent error message, and <var>msgid</var> contains a unique
158
<p>If the optional second parameter is supplied with value <code>"s"</code>,
159
recursively remove all subdirectories as well.
163
<strong>See also:</strong> mkdir, confirm_recursive_rmdir.
164
</p></blockquote></div>
166
<p><a name="doc_002dconfirm_005frecursive_005frmdir"></a>
169
— Built-in Function: <var>val</var> = <b>confirm_recursive_rmdir</b> ()<var><a name="index-confirm_005frecursive_005frmdir-1983"></a></var><br>
170
— Built-in Function: <var>old_val</var> = <b>confirm_recursive_rmdir</b> (<var>new_val</var>)<var><a name="index-confirm_005frecursive_005frmdir-1984"></a></var><br>
171
<blockquote><p>Query or set the internal variable that controls whether Octave
172
will ask for confirmation before recursively removing a directory tree.
173
</p></blockquote></div>
175
<p><a name="doc_002dmkfifo"></a>
178
— Built-in Function: [<var>err</var>, <var>msg</var>] = <b>mkfifo</b> (<var>name, mode</var>)<var><a name="index-mkfifo-1985"></a></var><br>
179
<blockquote><p>Create a <var>fifo</var> special file named <var>name</var> with file mode <var>mode</var>
181
<p>If successful, <var>err</var> is 0 and <var>msg</var> is an empty string.
182
Otherwise, <var>err</var> is nonzero and <var>msg</var> contains a
183
system-dependent error message.
184
</p></blockquote></div>
186
<p><a name="doc_002dumask"></a>
189
— Built-in Function: <b>umask</b> (<var>mask</var>)<var><a name="index-umask-1986"></a></var><br>
190
<blockquote><p>Set the permission mask for file creation. The parameter <var>mask</var>
191
is an integer, interpreted as an octal number. If successful,
192
returns the previous value of the mask (as an integer to be
193
interpreted as an octal number); otherwise an error message is printed.
194
</p></blockquote></div>
196
<p><a name="doc_002dstat"></a>
199
— Built-in Function: [<var>info</var>, <var>err</var>, <var>msg</var>] = <b>stat</b> (<var>file</var>)<var><a name="index-stat-1987"></a></var><br>
200
— Built-in Function: [<var>info</var>, <var>err</var>, <var>msg</var>] = <b>lstat</b> (<var>file</var>)<var><a name="index-lstat-1988"></a></var><br>
201
<blockquote><p>Return a structure <var>s</var> containing the following information about
205
<dt><code>dev</code><dd>ID of device containing a directory entry for this file.
207
<br><dt><code>ino</code><dd>File number of the file.
209
<br><dt><code>mode</code><dd>File mode, as an integer. Use the functions <code>S_ISREG</code>,
210
<code>S_ISDIR</code>, <code>S_ISCHR</code>, <code>S_ISBLK</code>, <code>S_ISFIFO</code>,
211
<code>S_ISLNK</code>, or <code>S_ISSOCK</code> to extract information from this
214
<br><dt><code>modestr</code><dd>File mode, as a string of ten letters or dashes as would be returned by
217
<br><dt><code>nlink</code><dd>Number of links.
219
<br><dt><code>uid</code><dd>User ID of file's owner.
221
<br><dt><code>gid</code><dd>Group ID of file's group.
223
<br><dt><code>rdev</code><dd>ID of device for block or character special files.
225
<br><dt><code>size</code><dd>Size in bytes.
227
<br><dt><code>atime</code><dd>Time of last access in the same form as time values returned from
228
<code>time</code>. See <a href="Timing-Utilities.html#Timing-Utilities">Timing Utilities</a>.
230
<br><dt><code>mtime</code><dd>Time of last modification in the same form as time values returned from
231
<code>time</code>. See <a href="Timing-Utilities.html#Timing-Utilities">Timing Utilities</a>.
233
<br><dt><code>ctime</code><dd>Time of last file status change in the same form as time values
234
returned from <code>time</code>. See <a href="Timing-Utilities.html#Timing-Utilities">Timing Utilities</a>.
236
<br><dt><code>blksize</code><dd>Size of blocks in the file.
238
<br><dt><code>blocks</code><dd>Number of blocks allocated for file.
241
<p>If the call is successful <var>err</var> is 0 and <var>msg</var> is an empty
242
string. If the file does not exist, or some other error occurs, <var>s</var>
243
is an empty matrix, <var>err</var> is −1, and <var>msg</var> contains the
244
corresponding system error message.
246
<p>If <var>file</var> is a symbolic link, <code>stat</code> will return information
247
about the actual file that is referenced by the link. Use <code>lstat</code>
248
if you want information about the symbolic link itself.
252
<pre class="example"> [s, err, msg] = stat ("/vmlinuz")
275
<p><a name="doc_002dlstat"></a>
278
— Built-in Function: [<var>info</var>, <var>err</var>, <var>msg</var>] = <b>lstat</b> (<var>file</var>)<var><a name="index-lstat-1989"></a></var><br>
279
<blockquote><p>See stat.
280
</p></blockquote></div>
282
<p><a name="doc_002dfileattrib"></a>
285
— Function File: [<var>status</var>, <var>msg</var>, <var>msgid</var>] = <b>fileattrib</b> (<var>file</var>)<var><a name="index-fileattrib-1990"></a></var><br>
286
<blockquote><p>Return information about <var>file</var>.
288
<p>If successful, <var>status</var> is 1, with <var>result</var> containing a
289
structure with the following fields:
292
<dt><code>Name</code><dd>Full name of <var>file</var>.
293
<br><dt><code>archive</code><dd>True if <var>file</var> is an archive (Windows).
294
<br><dt><code>system</code><dd>True if <var>file</var> is a system file (Windows).
295
<br><dt><code>hidden</code><dd>True if <var>file</var> is a hidden file (Windows).
296
<br><dt><code>directory</code><dd>True if <var>file</var> is a directory.
297
<br><dt><code>UserRead</code><dt><code>GroupRead</code><dt><code>OtherRead</code><dd>True if the user (group; other users) has read permission for
299
<br><dt><code>UserWrite</code><dt><code>GroupWrite</code><dt><code>OtherWrite</code><dd>True if the user (group; other users) has write permission for
301
<br><dt><code>UserExecute</code><dt><code>GroupExecute</code><dt><code>OtherExecute</code><dd>True if the user (group; other users) has execute permission for
304
If an attribute does not apply (i.e., archive on a Unix system) then
305
the field is set to NaN.
307
<p>With no input arguments, return information about the current
310
<p>If <var>file</var> contains globbing characters, return information about
311
all the matching files.
315
<strong>See also:</strong> glob.
316
</p></blockquote></div>
318
<p><a name="doc_002disdir"></a>
321
— Function File: <b>isdir</b> (<var>f</var>)<var><a name="index-isdir-1991"></a></var><br>
322
<blockquote><p>Return true if <var>f</var> is a directory.
323
</p></blockquote></div>
325
<p><a name="doc_002dglob"></a>
328
— Built-in Function: <b>glob</b> (<var>pattern</var>)<var><a name="index-glob-1992"></a></var><br>
329
<blockquote><p>Given an array of strings (as a char array or a cell array) in
330
<var>pattern</var>, return a cell array of file names that match any of
331
them, or an empty cell array if no patterns match. Tilde expansion
332
is performed on each of the patterns before looking for matching file
335
<pre class="example"> glob ("/vm*")
341
<strong>See also:</strong> dir, ls, stat, readdir.
342
</p></blockquote></div>
344
<p><a name="doc_002dfnmatch"></a>
347
— Built-in Function: <b>fnmatch</b> (<var>pattern, string</var>)<var><a name="index-fnmatch-1993"></a></var><br>
348
<blockquote><p>Return 1 or zero for each element of <var>string</var> that matches any of
349
the elements of the string array <var>pattern</var>, using the rules of
350
filename pattern matching. For example,
352
<pre class="example"> fnmatch ("a*b", {"ab"; "axyzb"; "xyzab"})
357
<p><a name="doc_002dfile_005fin_005fpath"></a>
360
— Built-in Function: <b>file_in_path</b> (<var>path, file</var>)<var><a name="index-file_005fin_005fpath-1994"></a></var><br>
361
— Built-in Function: <b>file_in_path</b> (<var>path, file, "all"</var>)<var><a name="index-file_005fin_005fpath-1995"></a></var><br>
362
<blockquote><p>Return the absolute name of <var>file</var> if it can be found in
363
<var>path</var>. The value of <var>path</var> should be a colon-separated list of
364
directories in the format described for <code>path</code>. If no file
365
is found, return an empty matrix. For example,
367
<pre class="example"> file_in_path (EXEC_PATH, "sh")
370
<p>If the second argument is a cell array of strings, search each
371
directory of the path for element of the cell array and return
372
the first that matches.
374
<p>If the third optional argument <code>"all"</code> is supplied, return
375
a cell array containing the list of all files that have the same
376
name in the path. If no files are found, return an empty cell array.
380
<strong>See also:</strong> file_in_loadpath.
381
</p></blockquote></div>
383
<p><a name="doc_002dtilde_005fexpand"></a>
386
— Built-in Function: <b>tilde_expand</b> (<var>string</var>)<var><a name="index-tilde_005fexpand-1996"></a></var><br>
387
<blockquote><p>Performs tilde expansion on <var>string</var>. If <var>string</var> begins with a
388
tilde character, (‘<samp><span class="samp">~</span></samp>’), all of the characters preceding the first
389
slash (or all characters, if there is no slash) are treated as a
390
possible user name, and the tilde and the following characters up to the
391
slash are replaced by the home directory of the named user. If the
392
tilde is followed immediately by a slash, the tilde is replaced by the
393
home directory of the user running Octave. For example,
395
<pre class="example"> tilde_expand ("~joeuser/bin")
397
tilde_expand ("~/bin")
402
<p><a name="doc_002dcanonicalize_005ffile_005fname"></a>
405
— Built-in Function: [<var>cname</var>, <var>status</var>, <var>msg</var>] <b>canonicalize_file_name</b> (<var>name</var>)<var><a name="index-canonicalize_005ffile_005fname-1997"></a></var><br>
406
<blockquote><p>Return the canonical name of file <var>name</var>.
407
</p></blockquote></div>
409
<p><a name="doc_002dmovefile"></a>
412
— Function File: [<var>status</var>, <var>msg</var>, <var>msgid</var>] = <b>movefile</b> (<var>f1, f2</var>)<var><a name="index-movefile-1998"></a></var><br>
413
<blockquote><p>Move the file <var>f1</var> to the new name <var>f2</var>. The name <var>f1</var>
414
may contain globbing patterns. If <var>f1</var> expands to multiple file
415
names, <var>f2</var> must be a directory.
417
<p>If successful, <var>status</var> is 1, with <var>msg</var> and <var>msgid</var> empty\n\
418
character strings. Otherwise, <var>status</var> is 0, <var>msg</var> contains a\n\
419
system-dependent error message, and <var>msgid</var> contains a unique\n\
420
message identifier.\n\
424
<strong>See also:</strong> glob.
425
</p></blockquote></div>
427
<p><a name="doc_002dcopyfile"></a>
430
— Function File: [<var>status</var>, <var>msg</var>, <var>msgid</var>] = <b>copyfile</b> (<var>f1, f2, force</var>)<var><a name="index-copyfile-1999"></a></var><br>
431
<blockquote><p>Copy the file <var>f1</var> to the new name <var>f2</var>. The name <var>f1</var>
432
may contain globbing patterns. If <var>f1</var> expands to multiple file
433
names, <var>f2</var> must be a directory. If <var>force</var> is given and equals
434
the string "f" the copy operation will be forced.
436
<p>If successful, <var>status</var> is 1, with <var>msg</var> and <var>msgid</var> empty\n\
437
character strings. Otherwise, <var>status</var> is 0, <var>msg</var> contains a\n\
438
system-dependent error message, and <var>msgid</var> contains a unique\n\
439
message identifier.\n\
443
<strong>See also:</strong> glob, movefile.
444
</p></blockquote></div>
446
<p><a name="doc_002dfileparts"></a>
449
— Function File: [<var>dir</var>, <var>name</var>, <var>ext</var>, <var>ver</var>] = <b>fileparts</b> (<var>filename</var>)<var><a name="index-fileparts-2000"></a></var><br>
450
<blockquote><p>Return the directory, name, extension, and version components of
455
<strong>See also:</strong> fullfile.
456
</p></blockquote></div>
458
<p><a name="doc_002dfilesep"></a>
461
— Built-in Function: <b>filesep</b> ()<var><a name="index-filesep-2001"></a></var><br>
462
<blockquote><p>Return the system-dependent character used to separate directory names.
466
<strong>See also:</strong> pathsep, dir, ls.
467
</p></blockquote></div>
469
<p><a name="doc_002dfullfile"></a>
472
— Function File: <var>filename</var> = <b>fullfile</b> (<var>dir1, dir2, <small class="dots">...</small>, file</var>)<var><a name="index-fullfile-2002"></a></var><br>
473
<blockquote><p>Return a complete filename constructed from the given components.
477
<strong>See also:</strong> fileparts.
478
</p></blockquote></div>
480
<p><a name="doc_002dtempdir"></a>
483
— Function File: <var>dir</var> = <b>fullfile</b> ()<var><a name="index-fullfile-2003"></a></var><br>
484
<blockquote><p>Return the name of the system's directory for temporary files.
485
</p></blockquote></div>
487
<p><a name="doc_002dtempname"></a>
490
— Function File: filename = <b>tempname</b> ()<var><a name="index-tempname-2004"></a></var><br>
491
<blockquote><p>This function is an alias for <code>tmpnam</code>.
492
</p></blockquote></div>
494
<p><a name="doc_002dP_005ftmpdir"></a>
497
— Built-in Function: <b>P_tmpdir</b> ()<var><a name="index-P_005ftmpdir-2005"></a></var><br>
498
<blockquote><p>Return the default name of the directory for temporary files on
499
this system. The name of this directory is system dependent.
500
</p></blockquote></div>