📄 internal.c
字号:
return 1;
}
/* Strip the paths back to the folder they are in */
for(i = (_tcslen(szFinalPath) - 1); i > -1; i--)
if(szFinalPath[i] != _T('\\'))
szFinalPath[i] = _T('\0');
else
break;
_tcscat(szFinalPath,f.cFileName);
if ((f.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == FILE_ATTRIBUTE_DIRECTORY)
{
if(!SetRootPath(szFinalPath))
{
/* Change for /D */
if(bChangeDrive)
{
_tcsupr(szFinalPath);
GetPathCase(szFinalPath, szPath);
SetCurrentDirectory(szPath);
}
return 0;
}
}
}while(FindNextFile (hFile, &f));
/* Didnt find an directories */
LoadString(CMD_ModuleHandle, STRING_ERROR_PATH_NOT_FOUND, szMsg, RC_STRING_MAX_SIZE);
ConErrPrintf(szMsg);
nErrorLevel = 1;
return 1;
}
#endif
#ifdef INCLUDE_CMD_MKDIR
/* Helper funtion for mkdir to make directories in a path.
Dont use the api to decrease depence on libs */
BOOL
MakeFullPath(TCHAR * DirPath)
{
TCHAR path[MAX_PATH];
TCHAR *p = DirPath;
INT n;
if (p[0] && p[1] == _T(':'))
p += 2;
while (*p == _T('\\'))
p++; /* skip drive root */
while ((p = _tcschr(p, _T('\\'))) != NULL)
{
n = p - DirPath + 1;
memcpy(path, DirPath, n);
path[n] = _T('\0');
if( !CreateDirectory(path, NULL) &&
(GetLastError() != ERROR_ALREADY_EXISTS))
return FALSE;
p++;
}
if (GetLastError() == ERROR_ALREADY_EXISTS)
SetLastError(ERROR_SUCCESS);
return TRUE;
}
/*
* MD / MKDIR
*
*/
INT cmd_mkdir (LPTSTR cmd, LPTSTR param)
{
LPTSTR dir; /* pointer to the directory to change to */
LPTSTR place; /* used to search for the \ when no space is used */
LPTSTR *p = NULL;
INT argc;
nErrorLevel = 0;
if (!_tcsncmp (param, _T("/?"), 2))
{
ConOutResPaging(TRUE,STRING_MKDIR_HELP);
return 0;
}
/* check if there is no space between the command and the path */
if (param[0] == _T('\0'))
{
/* search for the \ or . so that both short & long names will work */
for (place = cmd; *place; place++)
if (*place == _T('.') || *place == _T('\\'))
break;
if (*place)
dir = place;
else
/* signal that there are no parameters */
dir = NULL;
}
else
{
p = split (param, &argc, FALSE);
if (argc > 1)
{
/*JPP 20-Jul-1998 use standard error message */
error_too_many_parameters (param);
freep (p);
return 1;
}
else
dir = p[0];
}
if (!dir)
{
ConErrResPuts (STRING_ERROR_REQ_PARAM_MISSING);
nErrorLevel = 1;
if(p != NULL)
freep (p);
return 1;
}
/* Add a \ at the end of the path is there isnt on already */
if (dir[_tcslen (dir) - 1] != _T('\\'))
_tcscat(dir,_T("\\"));
if (!MakeFullPath(dir))
{
if(GetLastError() == ERROR_PATH_NOT_FOUND)
{
ConErrResPuts(STRING_MD_ERROR2);
}
else
{
ErrorMessage (GetLastError(), _T("MD"));
}
nErrorLevel = 1;
freep (p);
return 1;
}
freep (p);
return 0;
}
#endif
#ifdef INCLUDE_CMD_RMDIR
/*
* RD / RMDIR
*
*/
BOOL DeleteFolder(LPTSTR FileName)
{
TCHAR Base[MAX_PATH];
TCHAR TempFileName[MAX_PATH];
HANDLE hFile;
WIN32_FIND_DATA f;
_tcscpy(Base,FileName);
_tcscat(Base,_T("\\*"));
hFile = FindFirstFile(Base, &f);
Base[_tcslen(Base) - 1] = _T('\0');
if (hFile != INVALID_HANDLE_VALUE)
{
do
{
if (!_tcscmp(f.cFileName, _T(".")) ||
!_tcscmp(f.cFileName, _T("..")))
continue;
_tcscpy(TempFileName,Base);
_tcscat(TempFileName,f.cFileName);
if(f.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
DeleteFolder(TempFileName);
else
{
SetFileAttributes(TempFileName,FILE_ATTRIBUTE_NORMAL);
if(!DeleteFile(TempFileName))
return 0;
}
}while (FindNextFile (hFile, &f));
FindClose (hFile);
}
return RemoveDirectory(FileName);
}
INT cmd_rmdir (LPTSTR cmd, LPTSTR param)
{
TCHAR dir[MAX_PATH]; /* pointer to the directory to change to */
char ch;
INT args;
LPTSTR *arg = NULL;
INT i;
BOOL RD_SUB = FALSE;
BOOL RD_QUIET = FALSE;
HANDLE hFile;
WIN32_FIND_DATA f;
INT res;
TCHAR szMsg[RC_STRING_MAX_SIZE];
TCHAR szFullPath[MAX_PATH];
if (!_tcsncmp (param, _T("/?"), 2))
{
ConOutResPaging(TRUE,STRING_RMDIR_HELP);
return 0;
}
nErrorLevel = 0;
arg = split (param, &args, FALSE);
if (args == 0)
{
/* only command given */
error_req_param_missing ();
freep (arg);
return 1;
}
dir[0] = 0;
/* check for options anywhere in command line */
for (i = 0; i < args; i++)
{
if (*arg[i] == _T('/'))
{
/*found a command, but check to make sure it has something after it*/
if (_tcslen (arg[i]) == 2)
{
ch = _totupper (arg[i][1]);
if (ch == _T('S'))
{
RD_SUB = TRUE;
}
else if (ch == _T('Q'))
{
RD_QUIET = TRUE;
}
}
}
else
{
/* get the folder name */
_tcscpy(dir,arg[i]);
}
}
if (dir[0] == _T('\0'))
{
/* No folder to remove */
ConErrResPuts(STRING_ERROR_REQ_PARAM_MISSING);
freep(arg);
return 1;
}
GetFullPathName(dir,MAX_PATH,szFullPath,NULL);
/* remove trailing \ if any, but ONLY if dir is not the root dir */
if (_tcslen (szFullPath) >= 2 && szFullPath[_tcslen (szFullPath) - 1] == _T('\\'))
szFullPath[_tcslen(szFullPath) - 1] = _T('\0');
if(RD_SUB)
{
/* ask if they want to delete evrything in the folder */
if (!RD_QUIET)
{
LoadString( CMD_ModuleHandle, STRING_DEL_HELP2, szMsg, RC_STRING_MAX_SIZE);
res = FilePromptYNA (szMsg);
if ((res == PROMPT_NO) || (res == PROMPT_BREAK))
{
freep(arg);
nErrorLevel = 1;
return 1;
}
}
}
else
{
/* check for files in the folder */
_tcscat(szFullPath,_T("\\*"));
hFile = FindFirstFile(szFullPath, &f);
if (hFile != INVALID_HANDLE_VALUE)
{
do
{
if (!_tcscmp(f.cFileName,_T(".")) ||
!_tcscmp(f.cFileName,_T("..")))
continue;
ConOutResPuts(STRING_RMDIR_HELP2);
freep(arg);
FindClose (hFile);
nErrorLevel = 1;
return 1;
}while (FindNextFile (hFile, &f));
FindClose (hFile);
}
/* reovme the \\* */
szFullPath[_tcslen(szFullPath) - 2] = _T('\0');
}
if (!DeleteFolder(szFullPath))
{
/* Couldnt delete the folder, clean up and print out the error */
ErrorMessage (GetLastError(), _T("RD"));
freep (arg);
nErrorLevel = 1;
return 1;
}
freep (arg);
return 0;
}
#endif
/*
* set the exitflag to true
*
*/
INT CommandExit (LPTSTR cmd, LPTSTR param)
{
if (!_tcsncmp (param, _T("/?"), 2))
{
ConOutResPaging(TRUE,STRING_EXIT_HELP);
/* Just make sure */
bExit = FALSE;
/* Dont exit */
return 0;
}
if (bc != NULL && _tcsnicmp(param,_T("/b"),2) == 0)
{
param += 2;
while (_istspace (*param))
param++;
if (_istdigit(*param))
nErrorLevel = _ttoi(param);
ExitBatch (NULL);
}
else
bExit = TRUE;
return 0;
}
#ifdef INCLUDE_CMD_REM
/*
* does nothing
*
*/
INT CommandRem (LPTSTR cmd, LPTSTR param)
{
if (!_tcsncmp (param, _T("/?"), 2))
{
ConOutResPaging(TRUE,STRING_REM_HELP);
}
return 0;
}
#endif /* INCLUDE_CMD_REM */
INT CommandShowCommands (LPTSTR cmd, LPTSTR param)
{
PrintCommandList ();
return 0;
}
INT CommandShowCommandsDetail (LPTSTR cmd, LPTSTR param)
{
PrintCommandListDetail ();
return 0;
}
/* EOF */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -