Mercurial > hg > octave-lyh
annotate scripts/miscellaneous/movefile.m @ 14207:57e3490094e1
Fix order of legend entries for plotyy. Bug # 35314.
* legend.m: Maintain the proper order of children for plotyy. Add demos.
author | Ben Abbott <bpabbott@mac.com> |
---|---|
date | Tue, 17 Jan 2012 07:30:06 -0500 |
parents | 72c96de7a403 |
children | 5d3a684236b0 |
rev | line source |
---|---|
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
12497
diff
changeset
|
1 ## Copyright (C) 2005-2012 John W. Eaton |
6047 | 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 | |
7016 | 7 ## the Free Software Foundation; either version 3 of the License, or (at |
8 ## your option) any later version. | |
6047 | 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 | |
7016 | 16 ## along with Octave; see the file COPYING. If not, see |
17 ## <http://www.gnu.org/licenses/>. | |
6047 | 18 |
19 ## -*- texinfo -*- | |
12211
11faa69c4eaa
Add S_ISBLK and family of functions to documentation.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
20 ## @deftypefn {Function File} {[@var{status}, @var{msg}, @var{msgid}] =} movefile (@var{f1}, @var{f2}) |
11faa69c4eaa
Add S_ISBLK and family of functions to documentation.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
21 ## @deftypefnx {Function File} {[@var{status}, @var{msg}, @var{msgid}] =} movefile (@var{f1}, @var{f2}, 'f') |
6047 | 22 ## Move the file @var{f1} to the new name @var{f2}. The name @var{f1} |
23 ## may contain globbing patterns. If @var{f1} expands to multiple file | |
12211
11faa69c4eaa
Add S_ISBLK and family of functions to documentation.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
24 ## names, @var{f2} must be a directory. If the force flag 'f' is given |
11faa69c4eaa
Add S_ISBLK and family of functions to documentation.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
25 ## then any existing files will be overwritten without prompting. |
6047 | 26 ## |
12211
11faa69c4eaa
Add S_ISBLK and family of functions to documentation.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
27 ## If successful, @var{status} is 1, with @var{msg} and @var{msgid} empty |
11faa69c4eaa
Add S_ISBLK and family of functions to documentation.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
28 ## character strings. Otherwise, @var{status} is 0, @var{msg} contains a |
11faa69c4eaa
Add S_ISBLK and family of functions to documentation.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
29 ## system-dependent error message, and @var{msgid} contains a unique |
11faa69c4eaa
Add S_ISBLK and family of functions to documentation.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
30 ## message identifier. |
11faa69c4eaa
Add S_ISBLK and family of functions to documentation.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
31 ## @seealso{rename, copyfile} |
6047 | 32 ## @end deftypefn |
33 | |
34 function [status, msg, msgid] = movefile (f1, f2, force) | |
35 | |
6679 | 36 max_cmd_line = 1024; |
6047 | 37 status = true; |
38 msg = ""; | |
39 msgid = ""; | |
40 | |
6210 | 41 ## FIXME -- maybe use the same method as in ls to allow users control |
42 ## over the command that is executed. | |
43 | |
11300
4ecc7bc5bc83
search PATH from environment for programs, not EXEC_PATH
John W. Eaton <jwe@octave.org>
parents:
10549
diff
changeset
|
44 if (ispc () && ! isunix () |
4ecc7bc5bc83
search PATH from environment for programs, not EXEC_PATH
John W. Eaton <jwe@octave.org>
parents:
10549
diff
changeset
|
45 && isempty (file_in_path (getenv ("PATH"), "mv.exe"))) |
6233 | 46 ## Windows. |
6210 | 47 cmd = "cmd /C move"; |
48 cmd_force_flag = "/Y"; | |
49 else | |
50 cmd = "mv"; | |
51 cmd_force_flag = "-f"; | |
52 endif | |
53 | |
6047 | 54 if (nargin == 2 || nargin == 3) |
6233 | 55 ## Input type check. |
56 if (! (ischar (f1) || iscellstr (f1))) | |
6679 | 57 error ("movefile: first argument must be a character string or a cell array of character strings"); |
6233 | 58 endif |
59 | |
60 if (! ischar (f2)) | |
6679 | 61 error ("movefile: second argument must be a character string"); |
6233 | 62 endif |
63 | |
6047 | 64 if (nargin == 3 && strcmp (force, "f")) |
7540
3422f39573b1
strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
Ben Abbott <bpabbott@mac.com>
parents:
7352
diff
changeset
|
65 cmd = cstrcat (cmd, " ", cmd_force_flag); |
6047 | 66 endif |
6069 | 67 |
6233 | 68 ## If f1 isn't a cellstr convert it to one. |
69 if (ischar (f1)) | |
70 f1 = cellstr (f1); | |
6069 | 71 endif |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
72 |
6679 | 73 ## If f1 has more than 1 element f2 must be a directory |
74 isdir = (exist (f2, "dir") != 0); | |
75 if (length(f1) > 1 && ! isdir) | |
76 error ("movefile: when moving multiple files, second argument must be a directory"); | |
77 endif | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
78 |
6233 | 79 ## Protect the file name(s). |
80 f1 = glob (f1); | |
7352 | 81 if (isempty (f1)) |
82 error ("movefile: no files to move"); | |
83 endif | |
6679 | 84 p1 = sprintf ("\"%s\" ", f1{:}); |
85 p2 = tilde_expand (f2); | |
6069 | 86 |
6679 | 87 if (isdir && length(p1) > max_cmd_line) |
88 l2 = length(p2) + length (cmd) + 6; | |
89 while (! isempty(f1)) | |
10549 | 90 p1 = sprintf ("\"%s\" ", f1{1}); |
91 f1(1) = []; | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
92 while (!isempty (f1) && (length(p1) + length(f1{1}) + l2 < |
10549 | 93 max_cmd_line)) |
94 p1 = sprintf ("%s\"%s\" ", p1, f1{1}); | |
95 f1(1) = []; | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
96 endwhile |
6679 | 97 |
11300
4ecc7bc5bc83
search PATH from environment for programs, not EXEC_PATH
John W. Eaton <jwe@octave.org>
parents:
10549
diff
changeset
|
98 if (ispc () && ! isunix () |
4ecc7bc5bc83
search PATH from environment for programs, not EXEC_PATH
John W. Eaton <jwe@octave.org>
parents:
10549
diff
changeset
|
99 && ! isempty (file_in_path (getenv ("PATH"), "cp.exe"))) |
10549 | 100 p1 = strrep (p1, "\\", "/"); |
101 p2 = strrep (p2, "\\", "/"); | |
102 endif | |
6398 | 103 |
10549 | 104 ## Move the file(s). |
105 [err, msg] = system (sprintf ("%s %s \"%s\"", cmd, p1, p2)); | |
106 if (err < 0) | |
107 status = false; | |
108 msgid = "movefile"; | |
109 endif | |
6679 | 110 endwhile |
111 else | |
11300
4ecc7bc5bc83
search PATH from environment for programs, not EXEC_PATH
John W. Eaton <jwe@octave.org>
parents:
10549
diff
changeset
|
112 if (ispc () && ! isunix () |
12497
1536ed546219
Fix bug #32443 preventing 'pkg install' on Windows platforms.
Rik <octave@nomad.inbox5.com>
parents:
12211
diff
changeset
|
113 && ! isempty (file_in_path (getenv ("PATH"), "cp.exe"))) |
10549 | 114 p1 = strrep (p1, "\\", "/"); |
115 p2 = strrep (p2, "\\", "/"); | |
6679 | 116 endif |
117 | |
118 ## Move the file(s). | |
6828 | 119 [err, msg] = system (sprintf ("%s %s \"%s\"", cmd, p1, p2)); |
6679 | 120 if (err < 0) |
10549 | 121 status = false; |
122 msgid = "movefile"; | |
6679 | 123 endif |
6047 | 124 endif |
125 else | |
126 print_usage (); | |
127 endif | |
128 endfunction |