Mercurial > octave
comparison scripts/miscellaneous/movefile.m @ 30241:ba4aebad10d1
Return logical status variable from file functions for Matlab compatibility.
* NEWS: Announce change.
* dirfns.cc (Frmdir): Update documentation. Change return status to true/false
rather than 1.0/0.0.
* copyfile.m: Update documentation. Change internal variable "sts" to logical
variable. Change any assignments to status to true/false.
* movefile.m: Update documentation. Change internal variable "sts" to logical
variable. Change any assignments to status to true/false.
* mkdir.m: Update documentation.
* mkdir.m (mkdir_recur): Change internal variable "status" to logical.
author | Rik <rik@octave.org> |
---|---|
date | Wed, 13 Oct 2021 10:36:20 -0700 |
parents | 7854d5752dd2 |
children | 796f54d4ddbf |
comparison
equal
deleted
inserted
replaced
30240:a0bcfaf04cc1 | 30241:ba4aebad10d1 |
---|---|
42 ## @var{f2}. | 42 ## @var{f2}. |
43 ## | 43 ## |
44 ## When the force flag @qcode{'f'} is given any existing files will be | 44 ## When the force flag @qcode{'f'} is given any existing files will be |
45 ## overwritten without prompting. | 45 ## overwritten without prompting. |
46 ## | 46 ## |
47 ## If successful, @var{status} is 1, and @var{msg}, @var{msgid} are empty | 47 ## If successful, @var{status} is logical 1, and @var{msg}, @var{msgid} are |
48 ## character strings (""). Otherwise, @var{status} is 0, @var{msg} contains a | 48 ## empty character strings (""). Otherwise, @var{status} is logical 0, |
49 ## system-dependent error message, and @var{msgid} contains a unique message | 49 ## @var{msg} contains a system-dependent error message, and @var{msgid} |
50 ## identifier. Note that the status code is exactly opposite that of the | 50 ## contains a unique message identifier. Note that the status code is exactly |
51 ## @code{system} command. | 51 ## opposite that of the @code{system} command. |
52 ## @seealso{rename, copyfile, unlink, delete, glob} | 52 ## @seealso{rename, copyfile, unlink, delete, glob} |
53 ## @end deftypefn | 53 ## @end deftypefn |
54 | 54 |
55 function [status, msg, msgid] = movefile (f1, f2, force) | 55 function [status, msg, msgid] = movefile (f1, f2, force) |
56 | 56 |
57 if (nargin < 1) | 57 if (nargin < 1) |
58 print_usage (); | 58 print_usage (); |
59 endif | 59 endif |
60 | 60 |
61 max_cmd_line = 1024; | 61 max_cmd_line = 1024; |
62 sts = 1; | 62 sts = true; |
63 msg = ""; | 63 msg = ""; |
64 msgid = ""; | 64 msgid = ""; |
65 | 65 |
66 ## FIXME: maybe use the same method as in ls to allow users control | 66 ## FIXME: maybe use the same method as in ls to allow users control |
67 ## over the command that is executed. | 67 ## over the command that is executed. |
97 isdir = isfolder (f2); | 97 isdir = isfolder (f2); |
98 if (numel (f1) > 1 && ! isdir) | 98 if (numel (f1) > 1 && ! isdir) |
99 if (nargout == 0) | 99 if (nargout == 0) |
100 error ("movefile: when copying multiple files, F2 must be a directory"); | 100 error ("movefile: when copying multiple files, F2 must be a directory"); |
101 else | 101 else |
102 status = 0; | 102 status = false; |
103 msg = "when copying multiple files, F2 must be a directory"; | 103 msg = "when copying multiple files, F2 must be a directory"; |
104 msgid = "movefile"; | 104 msgid = "movefile"; |
105 return; | 105 return; |
106 endif | 106 endif |
107 endif | 107 endif |
114 endif | 114 endif |
115 if (isempty (f1)) | 115 if (isempty (f1)) |
116 if (nargout == 0) | 116 if (nargout == 0) |
117 error ("movefile: no files to move"); | 117 error ("movefile: no files to move"); |
118 else | 118 else |
119 status = 0; | 119 status = false; |
120 msg = "no files to move"; | 120 msg = "no files to move"; |
121 msgid = "movefile"; | 121 msgid = "movefile"; |
122 return; | 122 return; |
123 endif | 123 endif |
124 endif | 124 endif |
145 ## Close old file(s) in editor | 145 ## Close old file(s) in editor |
146 __event_manager_file_remove__ (p1, p2); | 146 __event_manager_file_remove__ (p1, p2); |
147 ## Move the file(s). | 147 ## Move the file(s). |
148 [err, msg] = system (sprintf ('%s %s "%s"', cmd, p1, p2)); | 148 [err, msg] = system (sprintf ('%s %s "%s"', cmd, p1, p2)); |
149 if (err != 0) | 149 if (err != 0) |
150 sts = 0; | 150 sts = false; |
151 msgid = "movefile"; | 151 msgid = "movefile"; |
152 endif | 152 endif |
153 ## Load new file(s) in editor | 153 ## Load new file(s) in editor |
154 __event_manager_file_renamed__ (sts); | 154 __event_manager_file_renamed__ (sts); |
155 endwhile | 155 endwhile |
163 ## Close old file(s) in editor | 163 ## Close old file(s) in editor |
164 __event_manager_file_remove__ (p1, p2); | 164 __event_manager_file_remove__ (p1, p2); |
165 ## Move the file(s). | 165 ## Move the file(s). |
166 [err, msg] = system (sprintf ('%s %s "%s"', cmd, p1, p2)); | 166 [err, msg] = system (sprintf ('%s %s "%s"', cmd, p1, p2)); |
167 if (err != 0) | 167 if (err != 0) |
168 sts = 0; | 168 sts = false; |
169 msgid = "movefile"; | 169 msgid = "movefile"; |
170 endif | 170 endif |
171 ## Load new file(s) in editor | 171 ## Load new file(s) in editor |
172 __event_manager_file_renamed__ (sts); | 172 __event_manager_file_renamed__ (sts); |
173 endif | 173 endif |
174 | 174 |
175 if (nargout == 0) | 175 if (nargout == 0) |
176 if (sts == 0) | 176 if (! sts) |
177 error ("movefile: operation failed: %s", msg); | 177 error ("movefile: operation failed: %s", msg); |
178 endif | 178 endif |
179 else | 179 else |
180 status = sts; | 180 status = sts; |
181 endif | 181 endif |