2 * MOVE.C - move internal command.
7 * 14-Dec-1998 (Eric Kohl <ekohl@abo.rhein-zeitung.de>)
10 * 18-Jan-1999 (Eric Kohl <ekohl@abo.rhein-zeitung.de>)
12 * Preliminary version!!!
14 * 20-Jan-1999 (Eric Kohl <ekohl@abo.rhein-zeitung.de>)
17 * 27-Jan-1999 (Eric Kohl <ekohl@abo.rhein-zeitung.de>)
18 * Added help text ("/?").
19 * Added more error checks.
21 * 03-Feb-1999 (Eric Kohl <ekohl@abo.rhein-zeitung.de>)
24 * 30-Apr-2005 (Magnus Olsen) <magnus@greatlord.com>)
25 * Remove all hardcode string to En.rc
31 #ifdef INCLUDE_CMD_MOVE
34 #define OVERWRITE_NO 0
35 #define OVERWRITE_YES 1
36 #define OVERWRITE_ALL 2
37 #define OVERWRITE_CANCEL 3
40 static INT
Overwrite (LPTSTR fn
)
42 TCHAR szMsg
[RC_STRING_MAX_SIZE
];
46 LoadString(CMD_ModuleHandle
, STRING_MOVE_HELP1
, szMsg
, RC_STRING_MAX_SIZE
);
47 ConOutPrintf(szMsg
, fn
);
51 for (p
= inp
; _istspace(*p
); p
++)
54 if (*p
!= szMsg
[0] && *p
!= szMsg
[2])
64 INT
cmd_move (LPTSTR cmd
, LPTSTR param
)
66 TCHAR szMsg
[RC_STRING_MAX_SIZE
];
69 TCHAR szDestPath
[MAX_PATH
];
70 TCHAR szSrcPath
[MAX_PATH
];
73 WIN32_FIND_DATA findBuffer
;
76 BOOL bNothing
= FALSE
;
78 if (!_tcsncmp (param
, _T("/?"), 2))
81 ConOutPuts (_T("Moves files and renames files and directories.\n\n"
82 "To move one or more files:\n"
83 "MOVE [/N][/Y|/-Y][drive:][path]filename1[,...] destination\n"
85 "To rename a directory:\n"
86 "MOVE [/N][/Y|/-Y][drive:][path]dirname1 dirname2\n"
88 " [drive:][path]filename1 Specifies the location and name of the file\n"
89 " or files you want to move.\n"
90 " /N Nothing. Don everthing but move files or direcories.\n"
95 ConOutResPuts(STRING_MOVE_HELP2
);
100 arg
= split (param
, &argc
, FALSE
);
104 for (i
= 0; i
< argc
; i
++)
114 if (_totupper (*p
) == _T('Y'))
119 if (_totupper (*p
) == _T('Y'))
121 else if (_totupper (*p
) == _T('N'))
130 /* there must be at least two pathspecs */
131 error_req_param_missing ();
135 /* get destination */
136 GetFullPathName (arg
[argc
- 1], MAX_PATH
, szDestPath
, NULL
);
138 DebugPrintf (_T("Destination: %s\n"), szDestPath
);
142 for (i
= 0; i
< argc
- 1; i
++)
144 if (*arg
[i
] == _T('/'))
147 hFile
= FindFirstFile (arg
[i
], &findBuffer
);
148 if (hFile
== INVALID_HANDLE_VALUE
)
150 ErrorMessage (GetLastError (), arg
[i
]);
157 GetFullPathName (findBuffer
.cFileName
, MAX_PATH
, szSrcPath
, &pszFile
);
159 if (GetFileAttributes (szSrcPath
) & FILE_ATTRIBUTE_DIRECTORY
)
161 /* source is directory */
164 DebugPrintf (_T("Move directory \'%s\' to \'%s\'\n"),
165 szSrcPath
, szDestPath
);
169 MoveFile (szSrcPath
, szDestPath
);
176 if (IsExistingFile (szDestPath
))
178 /* destination exists */
179 if (GetFileAttributes (szDestPath
) & FILE_ATTRIBUTE_DIRECTORY
)
181 /* destination is existing directory */
183 TCHAR szFullDestPath
[MAX_PATH
];
185 _tcscpy (szFullDestPath
, szDestPath
);
186 _tcscat (szFullDestPath
, _T("\\"));
187 _tcscat (szFullDestPath
, pszFile
);
189 ConOutPrintf (_T("%s => %s"), szSrcPath
, szFullDestPath
);
193 if (MoveFile (szSrcPath
, szFullDestPath
))
194 LoadString(CMD_ModuleHandle
, STRING_MOVE_ERROR1
, szMsg
, RC_STRING_MAX_SIZE
);
196 LoadString(CMD_ModuleHandle
, STRING_MOVE_ERROR2
, szMsg
, RC_STRING_MAX_SIZE
);
202 /* destination is existing file */
205 /* must get the overwrite code */
206 if ((nOverwrite
= Overwrite (szDestPath
)))
209 if (nOverwrite
== OVERWRITE_ALL
)
210 *lpFlags
|= FLAG_OVERWRITE_ALL
;
212 ConOutPrintf (_T("%s => %s"), szSrcPath
, szDestPath
);
216 if (MoveFile (szSrcPath
, szDestPath
))
217 LoadString(CMD_ModuleHandle
, STRING_MOVE_ERROR1
, szMsg
, RC_STRING_MAX_SIZE
);
219 LoadString(CMD_ModuleHandle
, STRING_MOVE_ERROR2
, szMsg
, RC_STRING_MAX_SIZE
);
227 /* destination does not exist */
228 TCHAR szFullDestPath
[MAX_PATH
];
230 GetFullPathName (szDestPath
, MAX_PATH
, szFullDestPath
, NULL
);
232 ConOutPrintf (_T("%s => %s"), szSrcPath
, szFullDestPath
);
236 if (MoveFile (szSrcPath
, szFullDestPath
))
237 LoadString(CMD_ModuleHandle
, STRING_MOVE_ERROR1
, szMsg
, RC_STRING_MAX_SIZE
);
239 LoadString(CMD_ModuleHandle
, STRING_MOVE_ERROR2
, szMsg
, RC_STRING_MAX_SIZE
);
245 while (FindNextFile (hFile
, &findBuffer
));
255 #endif /* INCLUDE_CMD_MOVE */