6047
|
1 ## Copyright (C) 2005 John W. Eaton |
|
2 ## |
|
3 ## This file is part of Octave. |
|
4 ## |
|
5 ## Octave is free software; you can redistribute it and/or modify it |
|
6 ## under the terms of the GNU General Public License as published by |
|
7 ## the Free Software Foundation; either version 2, or (at your option) |
|
8 ## any later version. |
|
9 ## |
|
10 ## Octave is distributed in the hope that it will be useful, but |
|
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
13 ## General Public License for more details. |
|
14 ## |
|
15 ## You should have received a copy of the GNU General Public License |
|
16 ## along with Octave; see the file COPYING. If not, write to the Free |
|
17 ## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
18 ## 02110-1301, USA. |
|
19 |
|
20 ## -*- texinfo -*- |
6152
|
21 ## @deftypefn {Function File} {[@var{status}, @var{msg}, @var{msgid}] =} copyfile (@var{f1}, @var{f2}, @var{force}) |
|
22 ## Copy the file @var{f1} to the new name @var{f2}. The name @var{f1} |
6047
|
23 ## may contain globbing patterns. If @var{f1} expands to multiple file |
6152
|
24 ## names, @var{f2} must be a directory. If @var{force} is given and equals |
|
25 ## the string "f" the copy operation will be forced. |
6047
|
26 ## |
|
27 ## If successful, @var{status} is 1, with @var{msg} and @var{msgid} empty\n\ |
|
28 ## character strings. Otherwise, @var{status} is 0, @var{msg} contains a\n\ |
|
29 ## system-dependent error message, and @var{msgid} contains a unique\n\ |
|
30 ## message identifier.\n\ |
6152
|
31 ## @seealso{glob, movefile} |
6047
|
32 ## @end deftypefn |
|
33 |
|
34 function [status, msg, msgid] = copyfile (f1, f2, force) |
|
35 |
|
36 status = true; |
|
37 msg = ""; |
|
38 msgid = ""; |
|
39 |
6210
|
40 ## FIXME -- maybe use the same method as in ls to allow users control |
|
41 ## over the command that is executed. |
|
42 |
|
43 if (ispc () && ! isunix () && isempty (file_in_path (EXEC_PATH, "cp"))) |
|
44 cmd = "cmd /C xcopy /E"; |
|
45 cmd_force_flag = "/Y"; |
|
46 else |
|
47 cmd = "cp -r"; |
|
48 cmd_force_flag = "-f"; |
|
49 endif |
|
50 |
6047
|
51 if (nargin == 2 || nargin == 3) |
|
52 if (nargin == 3 && strcmp (force, "f")) |
6210
|
53 cmd = strcat (cmd, " ", cmd_force_flag); |
6047
|
54 endif |
6069
|
55 |
|
56 ## Allow cell input and protect the file name(s). |
|
57 if (iscellstr (f1)) |
|
58 f1 = sprintf("\"%s\" ", f1{:}); |
|
59 else |
|
60 f1 = sprintf("\"%s\" ", f1); |
|
61 endif |
|
62 |
|
63 [err, msg] = system (sprintf ("%s %s \"%s\"", cmd, f1, f2)); |
6047
|
64 if (err < 0) |
|
65 status = false; |
|
66 msgid = "copyfile"; |
|
67 endif |
|
68 else |
|
69 print_usage (); |
|
70 endif |
|
71 |
|
72 endfunction |