annotate scripts/miscellaneous/copyfile.m @ 6210:12b676a0b183 before-graphics-branch

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