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>)
27 #ifdef INCLUDE_CMD_MOVE
37 #define OVERWRITE_NO 0
38 #define OVERWRITE_YES 1
39 #define OVERWRITE_ALL 2
40 #define OVERWRITE_CANCEL 3
43 static INT Overwrite (LPTSTR fn)
48 ConOutPrintf (_T("Overwrite %s (Yes/No/All)? "), fn);
49 ConInString (inp, 10);
52 for (p=inp; _istspace (*p); p++)
55 if (*p != _T('Y') && *p != _T('A'))
65 INT cmd_move (LPTSTR cmd, LPTSTR param)
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 ConOutPuts (_T("Moves files and renames files and directories.\n\n"
96 "To move one or more files:\n"
97 "MOVE [/N][drive:][path]filename1[,...] destination\n"
99 "To rename a directory:\n"
100 "MOVE [/N][drive:][path]dirname1 dirname2\n"
102 " [drive:][path]filename1 Specifies the location and name of the file\n"
103 " or files you want to move.\n"
104 " /N Nothing. Don everthing but move files or direcories.\n"
106 "Current limitations:\n"
107 " - You can't move a file or directory from one drive to another.\n"
113 arg = split (param, &argc, FALSE);
117 for (i = 0; i < argc; i++)
127 if (_totupper (*p) == _T('Y'))
132 if (_totupper (*p) == _T('Y'))
134 else if (_totupper (*p) == _T('N'))
143 /* there must be at least two pathspecs */
144 error_req_param_missing ();
148 /* get destination */
149 GetFullPathName (arg[argc - 1], MAX_PATH, szDestPath, NULL);
151 DebugPrintf (_T("Destination: %s\n"), szDestPath);
155 for (i = 0; i < argc - 1; i++)
157 if (*arg[i] == _T('/'))
160 hFile = FindFirstFile (arg[i], &findBuffer);
161 if (hFile == INVALID_HANDLE_VALUE)
163 ErrorMessage (GetLastError (), arg[i]);
170 GetFullPathName (findBuffer.cFileName, MAX_PATH, szSrcPath, &pszFile);
172 if (GetFileAttributes (szSrcPath) & FILE_ATTRIBUTE_DIRECTORY)
174 /* source is directory */
177 DebugPrintf (_T("Move directory \'%s\' to \'%s\'\n"),
178 szSrcPath, szDestPath);
182 MoveFile (szSrcPath, szDestPath);
189 if (IsValidFileName (szDestPath))
191 /* destination exists */
192 if (GetFileAttributes (szDestPath) & FILE_ATTRIBUTE_DIRECTORY)
194 /* destination is existing directory */
196 TCHAR szFullDestPath[MAX_PATH];
198 _tcscpy (szFullDestPath, szDestPath);
199 _tcscat (szFullDestPath, _T("\\"));
200 _tcscat (szFullDestPath, pszFile);
202 ConOutPrintf (_T("%s => %s"), szSrcPath, szFullDestPath);
206 if (MoveFile (szSrcPath, szFullDestPath))
207 ConOutPrintf (_T("[OK]\n"));
209 ConOutPrintf (_T("[Error]\n"));
214 /* destination is existing file */
217 /* must get the overwrite code */
218 if ((nOverwrite = Overwrite (szDestPath)))
221 if (nOverwrite == OVERWRITE_ALL)
222 *lpFlags |= FLAG_OVERWRITE_ALL;
224 ConOutPrintf (_T("%s => %s"), szSrcPath, szDestPath);
228 if (MoveFile (szSrcPath, szDestPath))
229 ConOutPrintf (_T("[OK]\n"));
231 ConOutPrintf (_T("[Error]\n"));
238 /* destination does not exist */
239 TCHAR szFullDestPath[MAX_PATH];
241 GetFullPathName (szDestPath, MAX_PATH, szFullDestPath, NULL);
243 ConOutPrintf (_T("%s => %s"), szSrcPath, szFullDestPath);
247 if (MoveFile (szSrcPath, szFullDestPath))
248 ConOutPrintf (_T("[OK]\n"));
250 ConOutPrintf (_T("[Error]\n"));
255 while (FindNextFile (hFile, &findBuffer));
265 #endif /* INCLUDE_CMD_MOVE */