Mercurial > octave
comparison scripts/miscellaneous/copyfile.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 |
---|---|
36 ## directory. | 36 ## directory. |
37 ## | 37 ## |
38 ## When the force flag @qcode{'f'} is given any existing files will be | 38 ## When the force flag @qcode{'f'} is given any existing files will be |
39 ## overwritten without prompting. | 39 ## overwritten without prompting. |
40 ## | 40 ## |
41 ## If successful, @var{status} is 1, and @var{msg}, @var{msgid} are empty | 41 ## If successful, @var{status} is logical 1, and @var{msg}, @var{msgid} are |
42 ## character strings (""). Otherwise, @var{status} is 0, @var{msg} contains a | 42 ## empty character strings (""). Otherwise, @var{status} is logical 0, |
43 ## system-dependent error message, and @var{msgid} contains a unique message | 43 ## @var{msg} contains a system-dependent error message, and @var{msgid} |
44 ## identifier. Note that the status code is exactly opposite that of the | 44 ## contains a unique message identifier. Note that the status code is exactly |
45 ## @code{system} command. | 45 ## opposite that of the @code{system} command. |
46 ## @seealso{movefile, rename, unlink, delete, glob} | 46 ## @seealso{movefile, rename, unlink, delete, glob} |
47 ## @end deftypefn | 47 ## @end deftypefn |
48 | 48 |
49 function [status, msg, msgid] = copyfile (f1, f2, force) | 49 function [status, msg, msgid] = copyfile (f1, f2, force) |
50 | 50 |
51 if (nargin < 2) | 51 if (nargin < 2) |
52 print_usage (); | 52 print_usage (); |
53 endif | 53 endif |
54 | 54 |
55 max_cmd_line = 1024; | 55 max_cmd_line = 1024; |
56 sts = 1; | 56 sts = true; |
57 msg = ""; | 57 msg = ""; |
58 msgid = ""; | 58 msgid = ""; |
59 | 59 |
60 ## FIXME: Maybe use the same method as in ls to allow users control | 60 ## FIXME: Maybe use the same method as in ls to allow users control |
61 ## over the command that is executed. | 61 ## over the command that is executed. |
88 isdir = isfolder (f2); | 88 isdir = isfolder (f2); |
89 if (numel (f1) > 1 && ! isdir) | 89 if (numel (f1) > 1 && ! isdir) |
90 if (nargout == 0) | 90 if (nargout == 0) |
91 error ("copyfile: when copying multiple files, F2 must be a directory"); | 91 error ("copyfile: when copying multiple files, F2 must be a directory"); |
92 else | 92 else |
93 status = 0; | 93 status = false; |
94 msg = "when copying multiple files, F2 must be a directory"; | 94 msg = "when copying multiple files, F2 must be a directory"; |
95 msgid = "copyfile"; | 95 msgid = "copyfile"; |
96 return; | 96 return; |
97 endif | 97 endif |
98 endif | 98 endif |
105 endif | 105 endif |
106 if (isempty (f1)) | 106 if (isempty (f1)) |
107 if (nargout == 0) | 107 if (nargout == 0) |
108 error ("copyfile: no files to move"); | 108 error ("copyfile: no files to move"); |
109 else | 109 else |
110 status = 0; | 110 status = false; |
111 msg = "no files to move"; | 111 msg = "no files to move"; |
112 msgid = "copyfile"; | 112 msgid = "copyfile"; |
113 return; | 113 return; |
114 endif | 114 endif |
115 endif | 115 endif |
134 endif | 134 endif |
135 | 135 |
136 ## Copy the files. | 136 ## Copy the files. |
137 [err, msg] = system (sprintf ('%s %s"%s"', cmd, p1, p2)); | 137 [err, msg] = system (sprintf ('%s %s"%s"', cmd, p1, p2)); |
138 if (err != 0) | 138 if (err != 0) |
139 sts = 0; | 139 sts = false; |
140 msgid = "copyfile"; | 140 msgid = "copyfile"; |
141 break; | 141 break; |
142 endif | 142 endif |
143 endwhile | 143 endwhile |
144 else | 144 else |
149 endif | 149 endif |
150 | 150 |
151 ## Copy the files. | 151 ## Copy the files. |
152 [err, msg] = system (sprintf ('%s %s"%s"', cmd, p1, p2)); | 152 [err, msg] = system (sprintf ('%s %s"%s"', cmd, p1, p2)); |
153 if (err != 0) | 153 if (err != 0) |
154 sts = 0; | 154 sts = false; |
155 msgid = "copyfile"; | 155 msgid = "copyfile"; |
156 endif | 156 endif |
157 endif | 157 endif |
158 | 158 |
159 if (nargout == 0) | 159 if (nargout == 0) |
160 if (sts == 0) | 160 if (! sts) |
161 error ("copyfile: operation failed: %s", msg); | 161 error ("copyfile: operation failed: %s", msg); |
162 endif | 162 endif |
163 else | 163 else |
164 status = sts; | 164 status = sts; |
165 endif | 165 endif |