diff --git a/base/applications/cmdutils/attrib/attrib.c b/base/applications/cmdutils/attrib/attrib.c index 141ad49728..c3cdc83c40 100644 --- a/base/applications/cmdutils/attrib/attrib.c +++ b/base/applications/cmdutils/attrib/attrib.c @@ -91,7 +91,8 @@ INT PrintAttribute( LPWSTR pszPath, LPWSTR pszFile, - BOOL bRecurse) + BOOL bRecurse, + BOOL bDirectories) { WIN32_FIND_DATAW findData; HANDLE hFind; @@ -111,22 +112,30 @@ PrintAttribute( hFind = FindFirstFileW(szFullName, &findData); if (hFind == INVALID_HANDLE_VALUE) { - ErrorMessage(GetLastError(), pszFile); - return 1; - } + /* prepare full file name buffer */ + wcscpy(szFullName, pszPath); + pszFileName = szFullName + wcslen(szFullName); + /* append *.* */ + wcscpy(pszFileName, L"*.*"); + + hFind = FindFirstFileW(szFullName, &findData); + if (hFind == INVALID_HANDLE_VALUE) + { + if ((GetLastError() != ERROR_DIRECTORY) && (GetLastError() != ERROR_SHARING_VIOLATION)) + ErrorMessage(GetLastError(), pszFile); + return 1; + } + } do { - if (!(findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) - continue; - if (!wcscmp(findData.cFileName, L".") || !wcscmp(findData.cFileName, L"..")) continue; wcscpy(pszFileName, findData.cFileName); wcscat(pszFileName, L"\\"); - PrintAttribute(szFullName, pszFile, bRecurse); + PrintAttribute(szFullName, pszFile, bRecurse, bDirectories); } while(FindNextFileW(hFind, &findData)); FindClose(hFind); @@ -139,14 +148,19 @@ PrintAttribute( hFind = FindFirstFileW(szFullName, &findData); if (hFind == INVALID_HANDLE_VALUE) { - ErrorMessage(GetLastError(), pszFile); + if (GetLastError() != ERROR_FILE_NOT_FOUND) + ErrorMessage(GetLastError(), pszFile); return 1; } do { - if (findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) - continue; + if ((findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) && !bDirectories && (wcsicmp(findData.cFileName, pszFile) != 0)) + continue; + + if (!wcscmp(findData.cFileName, L".") || + !wcscmp(findData.cFileName, L"..")) + continue; wcscpy(pszFileName, findData.cFileName); @@ -164,7 +178,6 @@ PrintAttribute( return 0; } - static INT ChangeAttribute( @@ -229,7 +242,7 @@ ChangeAttribute( do { - if (findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) + if ((findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) && (wcsicmp(findData.cFileName, pszFile) != 0)) continue; wcscpy(pszFileName, findData.cFileName); @@ -364,7 +377,7 @@ int wmain(int argc, WCHAR *argv[]) szPath[len + 1] = UNICODE_NULL; } wcscpy(szFileName, L"*.*"); - PrintAttribute(szPath, szFileName, bRecurse); + PrintAttribute(szPath, szFileName, bRecurse, bDirectories); return 0; } @@ -381,7 +394,7 @@ int wmain(int argc, WCHAR *argv[]) *p = L'\0'; if (dwMask == 0) - PrintAttribute(szPath, szFileName, bRecurse); + PrintAttribute(szPath, szFileName, bRecurse, bDirectories); else ChangeAttribute(szPath, szFileName, dwMask, dwAttrib, bRecurse, bDirectories);