26#if defined (HAVE_CONFIG_H)
70static bool Vconfirm_recursive_rmdir =
true;
103 int nargin = args.length ();
111 retval =
octave_value (sys::env::get_current_directory ());
115 std::string
dirname = args(0).xstring_value (
"cd: DIR must be a string");
120 else if (nargout == 0)
122 std::string home_dir = sys::env::get_home_directory ();
124 if (! home_dir.empty ())
125 interp.chdir (home_dir);
140 return ovl (sys::env::get_current_directory ());
143DEFUN (readdir, args, ,
157 if (args.length () != 1)
160 std::string
dirname = args(0).xstring_value (
"readdir: DIR must be a string");
169 if (sys::get_dirlist (
dirname, dirlist, msg))
183DEFUN (__mkdir__, args, ,
192 int nargin = args.
length ();
194 if (nargin < 1 || nargin > 2)
201 std::string parent = args(0).xstring_value (
"mkdir: PARENT must be a string");
202 std::string dir = args(1).xstring_value (
"mkdir: DIR must be a string");
204 dirname = sys::file_ops::concat (parent, dir);
206 else if (nargin == 1)
207 dirname = args(0).xstring_value (
"mkdir: DIR must be a string");
214 return ovl (
true,
"directory exists",
"mkdir");
220 int status = sys::mkdir (
dirname, 0777, msg);
223 return ovl (
false, msg,
"mkdir");
225 return ovl (
true,
"",
"");
247 int nargin = args.length ();
249 if (nargin < 1 || nargin > 2)
252 std::string
dirname = args(0).xstring_value (
"rmdir: DIR must be a string");
254 std::string fulldir = sys::file_ops::tilde_expand (
dirname);
263 if (args(1).string_value () !=
"s")
264 error (R
"(rmdir: second argument must be "s" for recursive removal)");
268 if (interp.interactive ()
270 && Vconfirm_recursive_rmdir)
274 std::string prompt =
"remove entire contents of " + fulldir +
"? ";
282 status = sys::recursive_rmdir (fulldir, msg);
288 status = sys::rmdir (fulldir, msg);
296 error (
"rmdir: operation failed: %s", msg.c_str ());
301 retval =
ovl (
false, msg,
"rmdir");
303 retval =
ovl (
true,
"",
"");
321 if (args.length () != 2)
324 std::string from = args(0).xstring_value (
"link: OLD must be a string");
325 std::string to = args(1).xstring_value (
"link: NEW must be a string");
327 from = sys::file_ops::tilde_expand (from);
328 to = sys::file_ops::tilde_expand (to);
333 int status = sys::link (from, to, msg);
338 error (
"link: operation failed: %s", msg.c_str ());
343 retval =
ovl (-1.0, msg);
345 retval =
ovl (0.0,
"");
363 if (args.length () != 2)
366 std::string from = args(0).xstring_value (
"symlink: OLD must be a string");
367 std::string to = args(1).xstring_value (
"symlink: NEW must be a string");
369 from = sys::file_ops::tilde_expand (from);
370 to = sys::file_ops::tilde_expand (to);
375 int status = sys::symlink (from, to, msg);
380 error (
"symlink: operation failed: %s", msg.c_str ());
385 retval =
ovl (-1.0, msg);
387 retval =
ovl (0.0,
"");
406 if (args.length () != 1)
409 std::string
symlink = args(0).xstring_value (
"readlink: SYMLINK must be a string");
413 std::string result, msg;
415 int status = sys::readlink (
symlink, result, msg);
418 return ovl (
"", -1.0, msg);
420 return ovl (result, status,
"");
435 if (args.length () != 2)
438 std::string from = args(0).xstring_value (
"rename: OLD must be a string");
439 std::string to = args(1).xstring_value (
"rename: NEW must be a string");
441 from = sys::file_ops::tilde_expand (from);
442 to = sys::file_ops::tilde_expand (to);
451 int status = sys::rename (from, to, msg);
458 error (
"rename: operation failed: %s", msg.c_str ());
463 retval =
ovl (-1.0, msg);
465 retval =
ovl (0.0,
"");
526 if (args.length () != 1)
530 = args(0).xstring_vector_value (
"glob: PATTERN must be a string");
532 glob_match pattern (sys::file_ops::tilde_expand (pat));
578DEFUN (__wglob__, args, ,
634 if (args.length () == 0)
641 return ovl (
Cell (sys::windows_glob (pattern)));
691DEFUN (__fnmatch__, args, ,
709 if (args.length () != 2)
715 glob_match pattern (sys::file_ops::tilde_expand (pat));
720DEFUN (filesep, args, ,
733 int nargin = args.length ();
741 retval = sys::file_ops::dir_sep_str ();
744 std::string s = args(0).xstring_value (
"filesep: argument must be a string");
746 error (R
"(filesep: argument must be "all")");
748 retval = sys::file_ops::dir_sep_chars ();
754DEFUN (pathsep, args, ,
761 if (args.length () > 0)
767DEFUN (confirm_recursive_rmdir, args, nargout,
782 "confirm_recursive_rmdir");
785OCTAVE_END_NAMESPACE(octave)
static bool forced_interactive()
static std::string path_sep_str()
Provides threadsafe access to octave.
void file_renamed(bool load_new)
void file_remove(const std::string &old_name, const std::string &new_name)
string_vector glob() const
bool match(const std::string &str) const
octave_idx_type length() const
string_vector & sort(bool make_uniq=false)
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
#define DEFMETHOD(name, interp_name, args_name, nargout_name, doc)
Macro to define a builtin method.
#define DEFUN(name, args_name, nargout_name, doc)
Macro to define a builtin function.
#define DEFUNX(name, fname, args_name, nargout_name, doc)
Macro to define a builtin function with certain internal name.
#define DEFMETHODX(name, fname, interp_name, args_name, nargout_name, doc)
Macro to define a builtin method with certain internal name.
#define DEFALIAS(alias, name)
Macro to define an alias for another existing function name.
octave_value_list Freadlink(const octave_value_list &args, int)
octave_value_list Frename(octave::interpreter &interp, const octave_value_list &args, int nargout)
octave_value_list Frmdir(octave::interpreter &interp, const octave_value_list &args, int nargout)
octave_value_list Flink(const octave_value_list &args, int nargout)
octave_value_list Fsymlink(const octave_value_list &args, int nargout)
void error(const char *fmt,...)
int symlink(const std::string &old_name, const std::string &new_name)
std::string dirname(const std::string &path)
int chdir(const std::string &path_arg)
string_vector glob(const string_vector &pat)
octave_value_list ovl(const OV_Args &... args)
Construct an octave_value_list with less typing.
octave_value set_internal_variable(bool &var, const octave_value_list &args, int nargout, const char *nm)