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(GetModuleHandle(NULL
), 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 LoadString(GetModuleHandle(NULL
), STRING_MOVE_HELP2
, szMsg
, RC_STRING_MAX_SIZE
);
101 arg
= split (param
, &argc
, FALSE
);
105 for (i
= 0; i
< argc
; i
++)
115 if (_totupper (*p
) == _T('Y'))
120 if (_totupper (*p
) == _T('Y'))
122 else if (_totupper (*p
) == _T('N'))
131 /* there must be at least two pathspecs */
132 error_req_param_missing ();
136 /* get destination */
137 GetFullPathName (arg
[argc
- 1], MAX_PATH
, szDestPath
, NULL
);
139 DebugPrintf (_T("Destination: %s\n"), szDestPath
);
143 for (i
= 0; i
< argc
- 1; i
++)
145 if (*arg
[i
] == _T('/'))
148 hFile
= FindFirstFile (arg
[i
], &findBuffer
);
149 if (hFile
== INVALID_HANDLE_VALUE
)
151 ErrorMessage (GetLastError (), arg
[i
]);
158 GetFullPathName (findBuffer
.cFileName
, MAX_PATH
, szSrcPath
, &pszFile
);
160 if (GetFileAttributes (szSrcPath
) & FILE_ATTRIBUTE_DIRECTORY
)
162 /* source is directory */
165 DebugPrintf (_T("Move directory \'%s\' to \'%s\'\n"),
166 szSrcPath
, szDestPath
);
170 MoveFile (szSrcPath
, szDestPath
);
177 if (IsExistingFile (szDestPath
))
179 /* destination exists */
180 if (GetFileAttributes (szDestPath
) & FILE_ATTRIBUTE_DIRECTORY
)
182 /* destination is existing directory */
184 TCHAR szFullDestPath
[MAX_PATH
];
186 _tcscpy (szFullDestPath
, szDestPath
);
187 _tcscat (szFullDestPath
, _T("\\"));
188 _tcscat (szFullDestPath
, pszFile
);
190 ConOutPrintf (_T("%s => %s"), szSrcPath
, szFullDestPath
);
194 if (MoveFile (szSrcPath
, szFullDestPath
))
195 LoadString(GetModuleHandle(NULL
), STRING_MOVE_ERROR1
, szMsg
, RC_STRING_MAX_SIZE
);
197 LoadString(GetModuleHandle(NULL
), STRING_MOVE_ERROR2
, szMsg
, RC_STRING_MAX_SIZE
);
203 /* destination is existing file */
206 /* must get the overwrite code */
207 if ((nOverwrite
= Overwrite (szDestPath
)))
210 if (nOverwrite
== OVERWRITE_ALL
)
211 *lpFlags
|= FLAG_OVERWRITE_ALL
;
213 ConOutPrintf (_T("%s => %s"), szSrcPath
, szDestPath
);
217 if (MoveFile (szSrcPath
, szDestPath
))
218 LoadString(GetModuleHandle(NULL
), STRING_MOVE_ERROR1
, szMsg
, RC_STRING_MAX_SIZE
);
220 LoadString(GetModuleHandle(NULL
), STRING_MOVE_ERROR2
, szMsg
, RC_STRING_MAX_SIZE
);
228 /* destination does not exist */
229 TCHAR szFullDestPath
[MAX_PATH
];
231 GetFullPathName (szDestPath
, MAX_PATH
, szFullDestPath
, NULL
);
233 ConOutPrintf (_T("%s => %s"), szSrcPath
, szFullDestPath
);
237 if (MoveFile (szSrcPath
, szFullDestPath
))
238 LoadString(GetModuleHandle(NULL
), STRING_MOVE_ERROR1
, szMsg
, RC_STRING_MAX_SIZE
);
240 LoadString(GetModuleHandle(NULL
), STRING_MOVE_ERROR2
, szMsg
, RC_STRING_MAX_SIZE
);
246 while (FindNextFile (hFile
, &findBuffer
));
256 #endif /* INCLUDE_CMD_MOVE */