⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 del.c

📁 ReactOS是一些高手根据Windows XP的内核编写出的类XP。内核实现机理和API函数调用几乎相同。甚至可以兼容XP的程序。喜欢研究系统内核的人可以看一看。
💻 C
📖 第 1 页 / 共 2 页
字号:
		                ErrorMessage (GetLastError(), _T(""));
//                                FindClose(hFile);
//                                return -1;
	                }
                }
                while (FindNextFile (hFile, &f));
	        FindClose (hFile);
        }
        return dwFiles;
}


static DWORD 
ProcessDirectory(LPTSTR FileName, DWORD* dwFlags, DWORD dwAttrFlags)
{
        TCHAR szFullPath[MAX_PATH];
        LPTSTR pFilePart;
        LPTSTR pSearchPart;
        HANDLE hFile;
        WIN32_FIND_DATA f;
        DWORD dwFiles = 0;

        GetFullPathName (FileName,
                         MAX_PATH,
                         szFullPath,
                         &pFilePart);

        dwFiles = DeleteFiles(szFullPath, dwFlags, dwAttrFlags);
        if (dwFiles & 0x80000000)
                return dwFiles;

        if (*dwFlags & DEL_SUBDIR)
        {
	        /* Get just the file name */
	        pSearchPart = _tcsrchr(FileName,_T('\\'));
	        if(pSearchPart != NULL)
		        pSearchPart++;
	        else
		        pSearchPart = FileName;

	        /* Get the full path to the file */
	        GetFullPathName (FileName,MAX_PATH,szFullPath,NULL);

	        /* strip the filename off of it */
                pFilePart = _tcsrchr(szFullPath, _T('\\'));
                if (pFilePart == NULL)
                {
                        pFilePart = szFullPath;
                }
                else
                {
                        pFilePart++;
                }

                _tcscpy(pFilePart, _T("*"));

                hFile = FindFirstFile(szFullPath, &f);
                if (hFile != INVALID_HANDLE_VALUE)
                {
                        do
                        {
       		                if (!(f.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ||
                                    !_tcscmp(f.cFileName, _T(".")) ||
                                    !_tcscmp(f.cFileName, _T("..")))
		                        continue;

                                _tcscpy(pFilePart, f.cFileName);
                                _tcscat(pFilePart, _T("\\"));
                                _tcscat(pFilePart, pSearchPart);

                                dwFiles +=ProcessDirectory(szFullPath, dwFlags, dwAttrFlags);
                                if (dwFiles & 0x80000000)
                                {
                                    break;
                                }
                        }
                        while (FindNextFile (hFile, &f));
	                FindClose (hFile);
                }
        }
        return dwFiles;
}        



INT CommandDelete (LPTSTR cmd, LPTSTR param)
{
	/*cmd is the command that was given, in this case it will always be "del" or "delete"
	param is whatever is given after the command*/

	LPTSTR *arg = NULL;
	INT args;
	INT i;
	INT   nEvalArgs = 0; /* nunber of evaluated arguments */
	DWORD dwFlags = 0;
	DWORD dwAttrFlags = 0;
	DWORD dwFiles = 0;
	LONG ch;
	TCHAR szOrginalArg[MAX_PATH];

	/*checks the first two chars of param to see if it is /?
	this however allows the following command to not show help
	"del frog.txt /?" */

        if (!StringsLoaded)
        {
                LoadStrings();
        }

	if (!_tcsncmp (param, _T("/?"), 2))
	{
		ConOutResPaging(TRUE,STRING_DEL_HELP1);
		return 0;
	}

	nErrorLevel = 0;

	arg = split (param, &args, FALSE);

	if (args == 0)
	{
		/* only command given */
		error_req_param_missing ();
		freep (arg);
		return 1;
	}
	/* 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('N'))
				{
					dwFlags |= DEL_NOTHING;
				}
				else if (ch == _T('P'))
				{
					dwFlags |= DEL_PROMPT;
				}
				else if (ch == _T('Q'))
				{
					dwFlags |= DEL_QUIET;
				}
				else if (ch == _T('F'))
				{
					dwFlags |= DEL_FORCE;
				}
				else if (ch == _T('S'))
				{
					dwFlags |= DEL_SUBDIR;
				}
				else if (ch == _T('T'))
				{
					dwFlags |= DEL_TOTAL;
				}
				else if (ch == _T('W'))
				{
					dwFlags |= DEL_WIPE;
				}
				else if (ch == _T('Y'))
				{
					dwFlags |= DEL_YES;
				}
				else if (ch == _T('A'))
				{

					dwFlags |= DEL_ATTRIBUTES;
					/*the proper syntax for /A has a min of 4 chars
					i.e. /A:R or /A:-H */
					if (_tcslen (arg[i]) < 4)
					{
						error_invalid_parameter_format(arg[i]);
						return 0;
					}
					ch = _totupper (arg[i][3]);
					if (_tcslen (arg[i]) == 4)
					{						
						if(ch == _T('A'))
						{
							dwAttrFlags |= ATTR_ARCHIVE;
						}
						if(ch == _T('H'))
						{
							dwAttrFlags |= ATTR_HIDDEN;
						}
						if(ch == _T('S'))
						{
							dwAttrFlags |= ATTR_SYSTEM;
						}
						if(ch == _T('R'))
						{
							dwAttrFlags |= ATTR_READ_ONLY;
						}
					}
					if (_tcslen (arg[i]) == 5)
					{
						if(ch == _T('-'))
						{
							ch = _totupper (arg[i][4]);
							if(ch == _T('A'))
							{
								dwAttrFlags |= ATTR_N_ARCHIVE;
							}
							if(ch == _T('H'))
							{
								dwAttrFlags |= ATTR_N_HIDDEN;
							}
							if(ch == _T('S'))
							{
								dwAttrFlags |= ATTR_N_SYSTEM;
							}
							if(ch == _T('R'))
							{
								dwAttrFlags |= ATTR_N_READ_ONLY;
							}
						}
					}
				}
			}

			nEvalArgs++;
		}
	}

	/* there are only options on the command line --> error!!!
	there is the same number of args as there is flags, so none of the args were filenames*/
	if (args == nEvalArgs)
	{
		error_req_param_missing ();
		freep (arg);
		return 1;
	}

	/* keep quiet within batch files */
	if (bc != NULL)
		dwFlags |= DEL_QUIET;

	/* check for filenames anywhere in command line */
	for (i = 0; i < args && !(dwFiles & 0x80000000); i++)
	{

                /*this checks to see if it isnt a flag, if it isnt, we assume it is a file name*/
		if((*arg[i] == _T('/')) || (*arg[i] == _T('-')))
			continue;

		/* We want to make a copies of the argument */
		if(_tcslen(arg[i]) == 2 && arg[i][1] == _T(':'))
		{
			/* Check for C: D: ... */
			GetRootPath(arg[i],szOrginalArg,MAX_PATH);
		}
		else
		{
			_tcscpy(szOrginalArg,arg[i]);
		}
                dwFiles += ProcessDirectory(szOrginalArg, &dwFlags, dwAttrFlags);

        }
	
	freep (arg);

	/*Based on MS cmd, we only tell what files are being deleted when /S is used */
	if (dwFlags & DEL_TOTAL)
	{
                dwFiles &= 0x7fffffff;
		if (dwFiles < 2)
		{
                        ConOutPrintf(szDelHelp3, dwFiles);
		}
		else
		{
			ConOutPrintf(szDelHelp4, dwFiles);
		}
	}

	return 0;
}


#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -