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 system-dependent\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\
234 When creating a directory permissions will be set to\n\
235 @code{0777 - @var{umask}}.\n\
236 @seealso{rmdir, pwd, cd, umask}\n\
241 retval(2) = std::string ();
242 retval(1) = std::string ();
245 int nargin = args.
length ();
251 std::string parent = args(0).string_value ();
252 std::string dir = args(1).string_value ();
262 else if (nargin == 1)
264 dirname = args(0).string_value ();
273 if (nargin == 1 || nargin == 2)
287 retval(1) =
"directory exists";
311 @deftypefn {Built-in Function} {} rmdir @var{dir}\n\
312 @deftypefnx {Built-in Function} {} rmdir (@var{dir}, \"s\")\n\
313 @deftypefnx {Built-in Function} {[@var{status}, @var{msg}, @var{msgid}] =} rmdir (@dots{})\n\
314 Remove the directory named @var{dir}.\n\
316 If the optional second parameter is supplied with value @qcode{\"s\"},\n\
317 recursively remove all subdirectories as well.\n\
319 If successful, @var{status} is 1, and @var{msg}, @var{msgid} are empty\n\
320 character strings (""). Otherwise, @var{status} is 0, @var{msg} contains a\n\
321 system-dependent error message, and @var{msgid} contains a unique message\n\
324 @seealso{mkdir, confirm_recursive_rmdir, pwd}\n\
329 retval(2) = std::string ();
330 retval(1) = std::string ();
333 int nargin = args.
length ();
335 if (nargin == 1 || nargin == 2)
337 std::string dirname = args(0).string_value ();
349 if (args(1).string_value () ==
"s")
357 =
"remove entire contents of " + fulldir +
"? ";
366 error (
"rmdir: expecting second argument to be \"s\"");
388 @deftypefn {Built-in Function} {} link @var{old} @var{new}\n\
389 @deftypefnx {Built-in Function} {[@var{err}, @var{msg}] =} link (@var{old}, @var{new})\n\
390 Create a new link (also known as a hard link) to an existing file.\n\
392 If successful, @var{err} is 0 and @var{msg} is an empty string.\n\
393 Otherwise, @var{err} is nonzero and @var{msg} contains a system-dependent\n\
395 @seealso{symlink, unlink, readlink, lstat}\n\
400 retval(1) = std::string ();
403 if (args.length () == 2)
405 std::string from = args(0).string_value ();
411 std::string to = args(1).string_value ();
435 @deftypefn {Built-in Function} {} symlink @var{old} @var{new}\n\
436 @deftypefnx {Built-in Function} {[@var{err}, @var{msg}] =} symlink (@var{old}, @var{new})\n\
437 Create a symbolic link @var{new} which contains the string @var{old}.\n\
439 If successful, @var{err} is 0 and @var{msg} is an empty string.\n\
440 Otherwise, @var{err} is nonzero and @var{msg} contains a system-dependent\n\
442 @seealso{link, unlink, readlink, lstat}\n\
447 retval(1) = std::string ();
450 if (args.length () == 2)
452 std::string from = args(0).string_value ();
458 std::string to = args(1).string_value ();
482 @deftypefn {Built-in Function} {} readlink @var{symlink}\n\
483 @deftypefnx {Built-in Function} {[@var{result}, @var{err}, @var{msg}] =} readlink (@var{symlink})\n\
484 Read the value of the symbolic link @var{symlink}.\n\
486 If successful, @var{result} contains the contents of the symbolic link\n\
487 @var{symlink}, @var{err} is 0, and @var{msg} is an empty string.\n\
488 Otherwise, @var{err} is nonzero and @var{msg} contains a system-dependent\n\
490 @seealso{lstat, symlink, link, unlink, delete}\n\
495 retval(2) = std::string ();
497 retval(0) = std::string ();
499 if (args.length () == 1)
501 std::string symlink = args(0).string_value ();
526 @deftypefn {Built-in Function} {} rename @var{old} @var{new}\n\
527 @deftypefnx {Built-in Function} {[@var{err}, @var{msg}] =} rename (@var{old}, @var{new})\n\
528 Change the name of file @var{old} to @var{new}.\n\
530 If successful, @var{err} is 0 and @var{msg} is an empty string.\n\
531 Otherwise, @var{err} is nonzero and @var{msg} contains a system-dependent\n\
533 @seealso{movefile, copyfile, ls, dir}\n\
538 retval(1) = std::string ();
541 if (args.length () == 2)
543 std::string from = args(0).string_value ();
549 std::string to = args(1).string_value ();
573 @deftypefn {Built-in Function} {} glob (@var{pattern})\n\
574 Given an array of pattern strings (as a char array or a cell array) in\n\
575 @var{pattern}, return a cell array of file names that match any of\n\
576 them, or an empty cell array if no patterns match.\n\
578 The pattern strings are interpreted as filename globbing patterns (as they\n\
579 are used by Unix shells).\n\
585 matches any string, including the null string,\n\
588 matches any single character, and\n\
591 matches any of the enclosed characters.\n\
594 Tilde expansion is performed on each of the patterns before looking for\n\
595 matching file names. For example:\n\
600 file1 file2 file3 myfile1 myfile1b\n\
607 glob (\"myfile?\")\n\
612 glob (\"file[12]\")\n\
619 @seealso{ls, dir, readdir, what}\n\
624 if (args.length () == 1)
675 DEFUN (__fnmatch__, args, ,
677 @deftypefn {Built-in Function} {} fnmatch (@var{pattern}, @var{string})\n\
678 Return true or false for each element of @var{string} that matches any of\n\
679 the elements of the string array @var{pattern}, using the rules of\n\
681 filename pattern matching. For example:\n\
685 fnmatch (\"a*b\", @{\"ab\"; \"axyzb\"; \"xyzab\"@})\n\
686 @result{} [ 1; 1; 0 ]\n\
689 @seealso{glob, regexp}\n\
694 if (args.length () == 2)
705 retval = pattern.
match (str);
714 DEFUN (filesep, args, ,
716 @deftypefn {Built-in Function} {} filesep ()\n\
717 @deftypefnx {Built-in Function} {} filesep (\"all\")\n\
718 Return the system-dependent character used to separate directory names.\n\
720 If @qcode{\"all\"} is given, the function returns all valid file separators\n\
721 in the form of a string. The list of file separators is system-dependent.\n\
722 It is @samp{/} (forward slash) under UNIX or @w{Mac OS X}, @samp{/} and\n\
723 @samp{\\} (forward and backward slashes) under Windows.\n\
729 if (args.length () == 0)
731 else if (args.length () == 1)
733 std::string s = args(0).string_value ();
751 DEFUN (pathsep, args, nargout,
753 @deftypefn {Built-in Function} {@var{val} =} pathsep ()\n\
754 @deftypefnx {Built-in Function} {@var{old_val} =} pathsep (@var{new_val})\n\
755 Query or set the character used to separate directories in a path.\n\
761 int nargin = args.
length ();
763 if (nargout > 0 || nargin == 0)
768 std::string sval = args(0).string_value ();
772 switch (sval.length ())
783 error (
"pathsep: argument must be a single character");
788 error (
"pathsep: argument must be a single character");
796 DEFUN (confirm_recursive_rmdir, args, nargout,
798 @deftypefn {Built-in Function} {@var{val} =} confirm_recursive_rmdir ()\n\
799 @deftypefnx {Built-in Function} {@var{old_val} =} confirm_recursive_rmdir (@var{new_val})\n\
800 @deftypefnx {Built-in Function} {} confirm_recursive_rmdir (@var{new_val}, \"local\")\n\
801 Query or set the internal variable that controls whether Octave\n\
802 will ask for confirmation before recursively removing a directory tree.\n\
804 When called from inside a function with the @qcode{\"local\"} option, the\n\
805 variable is changed locally for the function and any subroutines it calls.\n\
806 The original variable value is restored when exiting the function.\n\
OCTAVE_EXPORT octave_value_list Freadlink(const octave_value_list &args, int)
int octave_rename(const std::string &from, const std::string &to)
void gripe_wrong_type_arg(const char *name, const char *s, bool is_error)
static std::string path_sep_str(void)
OCTINTERP_API void print_usage(void)
static void change_directory(const std::string &dir)
static int octave_change_to_directory(const std::string &newdir)
octave_idx_type length(void) const
OCTAVE_EXPORT octave_value_list Frmdir(const octave_value_list &args, int)
#define DEFUN(name, args_name, nargout_name, doc)
void error(const char *fmt,...)
int octave_symlink(const std::string &old_name, const std::string &new_name)
#define SET_INTERNAL_VARIABLE(NM)
int octave_link(const std::string &old_name, const std::string &new_name)
OCTAVE_EXPORT octave_value_list Flink(const octave_value_list &args, int)
int octave_mkdir(const std::string &nm, mode_t md)
static bool Vconfirm_recursive_rmdir
static std::string tilde_expand(const std::string &)
#define DEFALIAS(alias, name)
static std::string concat(const std::string &, const std::string &)
static char path_sep_char(void)
static std::string get_current_directory(void)
static bool chdir(const std::string &newdir)
OCTAVE_EXPORT octave_value_list Fsymlink(const octave_value_list &args, int)
#define DEFUNX(name, fname, args_name, nargout_name, doc)
bool match(const std::string &str) const
string_vector & sort(bool make_uniq=false)
octave_idx_type length(void) const
int octave_readlink(const std::string &path, std::string &result)
std::string error(void) const
static std::string dir_sep_chars(void)
octave_time Vlast_chdir_time
int octave_rmdir(const std::string &name)
OCTAVE_EXPORT octave_value_list Fmkdir(const octave_value_list &args, int)
OCTAVE_EXPORT octave_value_list Frename(const octave_value_list &args, int)
static std::string dir_sep_str(void)
int octave_recursive_rmdir(const std::string &name)
string_vector glob(void) const
return octave_value(v1.char_array_value().concat(v2.char_array_value(), ra_idx),((a1.is_sq_string()||a2.is_sq_string())? '\'': '"'))
static std::string get_home_directory(void)