comparison scripts/miscellaneous/movefile.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 67b1a61a85ce
children a299c8a6d96e
comparison
equal deleted inserted replaced
6209:15b299f6803d 6210:12b676a0b183
34 34
35 status = true; 35 status = true;
36 msg = ""; 36 msg = "";
37 msgid = ""; 37 msgid = "";
38 38
39 ## FIXME -- maybe use the same method as in ls to allow users control
40 ## over the command that is executed.
41
42 if (ispc () && ! isunix () && isempty (file_in_path (EXEC_PATH, "mv")))
43 cmd = "cmd /C move";
44 cmd_force_flag = "/Y";
45 else
46 cmd = "mv";
47 cmd_force_flag = "-f";
48 endif
49
39 if (nargin == 2 || nargin == 3) 50 if (nargin == 2 || nargin == 3)
40 if (nargin == 3 && strcmp (force, "f")) 51 if (nargin == 3 && strcmp (force, "f"))
41 cmd = "/bin/mv -f"; 52 cmd = strcat (cmd, " ", cmd_force_flag);
42 else
43 cmd = "/bin/mv";
44 endif 53 endif
45 54
46 ## Allow cell input and protect the file name(s). 55 ## Allow cell input and protect the file name(s).
47 if (iscellstr (f1)) 56 if (iscellstr (f1))
48 f1 = sprintf("\"%s\" ", f1{:}); 57 f1 = sprintf("\"%s\" ", f1{:});
57 endif 66 endif
58 else 67 else
59 print_usage (); 68 print_usage ();
60 endif 69 endif
61 70
62 ### status = true;
63 ### msg = "";
64 ### msgid = "movefile";
65 ###
66 ### if (nargin == 2)
67 ###
68 ### flist = glob (f1);
69 ### nfiles = numel (flist);
70 ### if (nfiles > 1)
71 ### [f2info, err, msg] = stat (f2);
72 ### if (err < 0)
73 ### status = false;
74 ### else
75 ### if (S_ISDIR (f2info.mode))
76 ### for i = 1:nfiles
77 ### [err, msg] = rename (flist{i}, f2);
78 ### if (err < 0)
79 ### status = false;
80 ### break;
81 ### endif
82 ### endfor
83 ### else
84 ### status = false;
85 ### msg = "when moving multiple files, destination must be a directory";
86 ### endif
87 ### endif
88 ### else
89 ### [err, msg] = rename (f1, f2);
90 ### if (err < 0)
91 ### status = false;
92 ### break;
93 ### endif
94 ### endif
95 ###
96 ### else
97 ### usage ("movefile (f1, f2)");
98 ### endif
99 ###
100 ### if (status)
101 ### msgid = "";
102 ### endif
103
104 endfunction 71 endfunction