36 #include <sys/types.h>
80 Vlast_chdir_time.
stamp ();
90 error (
"%s: %s", newdir.c_str (), gnulib::strerror (errno));
95 DEFUN (cd, args, nargout,
97 @deftypefn {Command} {} cd @var{dir}\n\
98 @deftypefnx {Command} {} cd\n\
99 @deftypefnx {Built-in Function} {@var{old_dir} =} cd @var{dir}\n\
100 @deftypefnx {Command} {} chdir @dots{}\n\
101 Change the current working directory to @var{dir}.\n\
103 If @var{dir} is omitted, the current directory is changed to the user's home\n\
104 directory (@qcode{\"~\"}).\n\
113 changes the current working directory to @file{~/octave}. If the\n\
114 directory does not exist, an error message is printed and the working\n\
115 directory is not changed.\n\
117 @code{chdir} is an alias for @code{cd} and can be used in all of the same\n\
120 Compatibility Note: When called with no arguments, @sc{matlab} prints the\n\
121 present working directory rather than changing to the user's home directory.\n\
122 @seealso{pwd, mkdir, rmdir, dir, ls}\n\
127 int argc = args.
length () + 1;
139 std::string dirname = argv[1];
141 if (dirname.length () > 0)
148 if (! home_dir.empty ())
159 @deftypefn {Built-in Function} {} pwd ()\n\
160 @deftypefnx {Built-in Function} {@var{dir} =} pwd ()\n\
161 Return the current working directory.\n\
162 @seealso{cd, dir, ls, mkdir, rmdir}\n\
168 DEFUN (readdir, args, ,
170 @deftypefn {Built-in Function} {@var{files} =} readdir (@var{dir})\n\
171 @deftypefnx {Built-in Function} {[@var{files}, @var{err}, @var{msg}] =} readdir (@var{dir})\n\
172 Return the names of files in the directory @var{dir} as a cell array of\n\
175 If an error occurs, return an empty cell array in @var{files}.\n\
176 If successful, @var{err} is 0 and @var{msg} is an empty string.\n\
177 Otherwise, @var{err} is nonzero and @var{msg} contains a\n\
178 system-dependent error message.\n\
179 @seealso{ls, dir, glob, what}\n\
184 retval(2) = std::string ();
188 if (args.length () == 1)
190 std::string dirname = args(0).string_value ();
206 retval(2) = dir.
error ();
221 @deftypefn {Built-in Function} {} mkdir @var{dir}\n\
222 @deftypefnx {Built-in Function} {} mkdir (@var{parent}, @var{dir})\n\
223 @deftypefnx {Built-in Function} {[@var{status}, @var{msg}, @var{msgid}] =} mkdir (@dots{})\n\
224 Create a directory named @var{dir} in the directory @var{parent}.\n\
226 If no @var{parent} directory is specified the present working directory is\n\
229 If successful, @var{status} is 1, and @var{msg}, @var{msgid} are empty\n\
230 character strings (""). Otherwise, @var{status} is 0, @var{msg} contains a\n\
231 system-dependent error message, and @var{msgid} contains a unique message\n\
233 @seealso{rmdir, pwd, cd}\n\
238 retval(2) = std::string ();
239 retval(1) = std::string ();
242 int nargin = args.
length ();
248 std::string parent = args(0).string_value ();
249 std::string dir = args(1).string_value ();
259 else if (nargin == 1)
261 dirname = args(0).string_value ();
270 if (nargin == 1 || nargin == 2)
284 retval(1) =
"directory exists";
308 @deftypefn {Built-in Function} {} rmdir @var{dir}\n\
309 @deftypefnx {Built-in Function} {} rmdir (@var{dir}, \"s\")\n\
310 @deftypefnx {Built-in Function} {[@var{status}, @var{msg}, @var{msgid}] =} rmdir (@dots{})\n\
311 Remove the directory named @var{dir}.\n\
313 If successful, @var{status} is 1, and @var{msg}, @var{msgid} are empty\n\
314 character strings (""). Otherwise, @var{status} is 0, @var{msg} contains a\n\
315 system-dependent error message, and @var{msgid} contains a unique message\n\
318 If the optional second parameter is supplied with value @qcode{\"s\"},\n\
319 recursively remove all subdirectories as well.\n\
320 @seealso{mkdir, confirm_recursive_rmdir, pwd}\n\
325 retval(2) = std::string ();
326 retval(1) = std::string ();
329 int nargin = args.
length ();
331 if (nargin == 1 || nargin == 2)
333 std::string dirname = args(0).string_value ();
345 if (args(1).string_value () ==
"s")
352 =
"remove entire contents of " + fulldir +
"? ";
361 error (
"rmdir: expecting second argument to be \"s\"");
383 @deftypefn {Built-in Function} {} link @var{old} @var{new}\n\
384 @deftypefnx {Built-in Function} {[@var{err}, @var{msg}] =} link (@var{old}, @var{new})\n\
385 Create a new link (also known as a hard link) to an existing file.\n\
387 If successful, @var{err} is 0 and @var{msg} is an empty string.\n\
388 Otherwise, @var{err} is nonzero and @var{msg} contains a\n\
389 system-dependent error message.\n\
390 @seealso{symlink, unlink, readlink, lstat}\n\
395 retval(1) = std::string ();
398 if (args.length () == 2)
400 std::string from = args(0).string_value ();
406 std::string to = args(1).string_value ();
430 @deftypefn {Built-in Function} {} symlink @var{old} @var{new}\n\
431 @deftypefnx {Built-in Function} {[@var{err}, @var{msg}] =} symlink (@var{old}, @var{new})\n\
432 Create a symbolic link @var{new} which contains the string @var{old}.\n\
434 If successful, @var{err} is 0 and @var{msg} is an empty string.\n\
435 Otherwise, @var{err} is nonzero and @var{msg} contains a\n\
436 system-dependent error message.\n\
437 @seealso{link, unlink, readlink, lstat}\n\
442 retval(1) = std::string ();
445 if (args.length () == 2)
447 std::string from = args(0).string_value ();
453 std::string to = args(1).string_value ();
477 @deftypefn {Built-in Function} {} readlink @var{symlink}\n\
478 @deftypefnx {Built-in Function} {[@var{result}, @var{err}, @var{msg}] =} readlink (@var{symlink})\n\
479 Read the value of the symbolic link @var{symlink}.\n\
481 If successful, @var{result} contains the contents of the symbolic link\n\
482 @var{symlink}, @var{err} is 0, and @var{msg} is an empty string.\n\
483 Otherwise, @var{err} is nonzero and @var{msg} contains a system-dependent\n\
485 @seealso{lstat, symlink, link, unlink, delete}\n\
490 retval(2) = std::string ();
492 retval(0) = std::string ();
494 if (args.length () == 1)
496 std::string symlink = args(0).string_value ();
521 @deftypefn {Built-in Function} {} rename @var{old} @var{new}\n\
522 @deftypefnx {Built-in Function} {[@var{err}, @var{msg}] =} rename (@var{old}, @var{new})\n\
523 Change the name of file @var{old} to @var{new}.\n\
525 If successful, @var{err} is 0 and @var{msg} is an empty string.\n\
526 Otherwise, @var{err} is nonzero and @var{msg} contains a\n\
527 system-dependent error message.\n\
528 @seealso{movefile, copyfile, ls, dir}\n\
533 retval(1) = std::string ();
536 if (args.length () == 2)
538 std::string from = args(0).string_value ();
544 std::string to = args(1).string_value ();
568 @deftypefn {Built-in Function} {} glob (@var{pattern})\n\
569 Given an array of pattern strings (as a char array or a cell array) in\n\
570 @var{pattern}, return a cell array of file names that match any of\n\
571 them, or an empty cell array if no patterns match. The pattern strings are\n\
572 interpreted as filename globbing patterns (as they are used by Unix shells).\n\
577 matches any string, including the null string,\n\
580 matches any single character, and\n\
583 matches any of the enclosed characters.\n\
586 Tilde expansion is performed on each of the patterns before looking for\n\
587 matching file names. For example:\n\
592 file1 file2 file3 myfile1 myfile1b\n\
599 glob (\"myfile?\")\n\
604 glob (\"file[12]\")\n\
611 @seealso{ls, dir, readdir, what, fnmatch}\n\
616 if (args.length () == 1)
669 @deftypefn {Built-in Function} {} fnmatch (@var{pattern}, @var{string})\n\
670 Return true or false for each element of @var{string} that matches any of\n\
671 the elements of the string array @var{pattern}, using the rules of\n\
672 filename pattern matching. For example:\n\
676 fnmatch (\"a*b\", @{\"ab\"; \"axyzb\"; \"xyzab\"@})\n\
677 @result{} [ 1; 1; 0 ]\n\
680 @seealso{glob, regexp}\n\
685 if (args.length () == 2)
696 retval = pattern.
match (str);
705 DEFUN (filesep, args, ,
707 @deftypefn {Built-in Function} {} filesep ()\n\
708 @deftypefnx {Built-in Function} {} filesep (\"all\")\n\
709 Return the system-dependent character used to separate directory names.\n\
711 If @qcode{\"all\"} is given, the function returns all valid file separators\n\
712 in the form of a string. The list of file separators is system-dependent.\n\
713 It is @samp{/} (forward slash) under UNIX or @w{Mac OS X}, @samp{/} and\n\
714 @samp{\\} (forward and backward slashes) under Windows.\n\
720 if (args.length () == 0)
722 else if (args.length () == 1)
724 std::string s = args(0).string_value ();
742 DEFUN (pathsep, args, nargout,
744 @deftypefn {Built-in Function} {@var{val} =} pathsep ()\n\
745 @deftypefnx {Built-in Function} {@var{old_val} =} pathsep (@var{new_val})\n\
746 Query or set the character used to separate directories in a path.\n\
752 int nargin = args.
length ();
754 if (nargout > 0 || nargin == 0)
759 std::string sval = args(0).string_value ();
763 switch (sval.length ())
774 error (
"pathsep: argument must be a single character");
779 error (
"pathsep: argument must be a single character");
787 DEFUN (confirm_recursive_rmdir, args, nargout,
789 @deftypefn {Built-in Function} {@var{val} =} confirm_recursive_rmdir ()\n\
790 @deftypefnx {Built-in Function} {@var{old_val} =} confirm_recursive_rmdir (@var{new_val})\n\
791 @deftypefnx {Built-in Function} {} confirm_recursive_rmdir (@var{new_val}, \"local\")\n\
792 Query or set the internal variable that controls whether Octave\n\
793 will ask for confirmation before recursively removing a directory tree.\n\
795 When called from inside a function with the @qcode{\"local\"} option, the\n\
796 variable is changed locally for the function and any subroutines it calls. \n\
797 The original variable value is restored when exiting the function.\n\