Improve rename support for when renaming files (in a folder) on a drive different from the current one.
Imported-from: https://svn.code.sf.net/p/dosbox/code-0/dosbox/trunk@3947
This commit is contained in:
parent
4aaa632bd9
commit
2a1ae6fb9c
1 changed files with 22 additions and 18 deletions
|
@ -233,34 +233,38 @@ void DOS_Shell::CMD_HELP(char * args){
|
|||
void DOS_Shell::CMD_RENAME(char * args){
|
||||
HELP("RENAME");
|
||||
StripSpaces(args);
|
||||
if(!*args) {SyntaxError();return;}
|
||||
if((strchr(args,'*')!=NULL) || (strchr(args,'?')!=NULL) ) { WriteOut(MSG_Get("SHELL_CMD_NO_WILD"));return;}
|
||||
if (!*args) {SyntaxError();return;}
|
||||
if ((strchr(args,'*')!=NULL) || (strchr(args,'?')!=NULL) ) { WriteOut(MSG_Get("SHELL_CMD_NO_WILD"));return;}
|
||||
char * arg1=StripWord(args);
|
||||
StripSpaces(args);
|
||||
if (!*args) {SyntaxError();return;}
|
||||
char* slash = strrchr(arg1,'\\');
|
||||
if(slash) {
|
||||
slash++;
|
||||
if (slash) {
|
||||
/* If directory specified (crystal caves installer)
|
||||
* rename from c:\X : rename c:\abc.exe abc.shr.
|
||||
* File must appear in C:\ */
|
||||
* File must appear in C:\
|
||||
* Ren X:\A\B C => ren X:\A\B X:\A\C */
|
||||
|
||||
char dir_source[DOS_PATHLENGTH]={0};
|
||||
char dir_source[DOS_PATHLENGTH + 4] = {0}; //not sure if drive portion is included in pathlength
|
||||
//Copy first and then modify, makes GCC happy
|
||||
strcpy(dir_source,arg1);
|
||||
safe_strncpy(dir_source,arg1,DOS_PATHLENGTH + 4);
|
||||
char* dummy = strrchr(dir_source,'\\');
|
||||
*dummy=0;
|
||||
|
||||
if((strlen(dir_source) == 2) && (dir_source[1] == ':'))
|
||||
strcat(dir_source,"\\"); //X: add slash
|
||||
|
||||
char dir_current[DOS_PATHLENGTH + 1];
|
||||
dir_current[0] = '\\'; //Absolute addressing so we can return properly
|
||||
DOS_GetCurrentDir(0,dir_current + 1);
|
||||
if(!DOS_ChangeDir(dir_source)) {
|
||||
if (!dummy) { //Possible due to length
|
||||
WriteOut(MSG_Get("SHELL_ILLEGAL_PATH"));
|
||||
return;
|
||||
}
|
||||
DOS_Rename(slash,args);
|
||||
DOS_ChangeDir(dir_current);
|
||||
dummy++;
|
||||
*dummy = 0;
|
||||
|
||||
//Maybe check args for directory, as I think that isn't allowed
|
||||
|
||||
//dir_source and target are introduced for when we support multiple files being renamed.
|
||||
char target[DOS_PATHLENGTH+CROSS_LEN + 5] = {0};
|
||||
strcpy(target,dir_source);
|
||||
strncat(target,args,CROSS_LEN);
|
||||
|
||||
DOS_Rename(arg1,target);
|
||||
|
||||
} else {
|
||||
DOS_Rename(arg1,args);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue