/////////////////////////////////////////////////////////////// // fileattr.cpp - extract attribute information from files // // // // Adapted by Jim Fawcett from the book: // // "Win32 System Services: // // The Heart of Windows 95 and Windows NT", Marshall Brain, // // Prentice Hall, Copyright 1995 // // // /////////////////////////////////////////////////////////////// #include #include #include using namespace std; //----< display file attributes >------------------------------ void ShowAttributes(DWORD attributes) // Shows the file attributes on stdout { if (attributes & FILE_ATTRIBUTE_ARCHIVE) cout << " archive\n"; if (attributes & FILE_ATTRIBUTE_DIRECTORY) cout << " directory\n"; if (attributes & FILE_ATTRIBUTE_HIDDEN) cout << " hidden\n"; if (attributes & FILE_ATTRIBUTE_NORMAL) cout << " normal\n"; if (attributes & FILE_ATTRIBUTE_READONLY) cout << " read only\n"; if (attributes & FILE_ATTRIBUTE_SYSTEM) cout << " system\n"; if (attributes & FILE_ATTRIBUTE_TEMPORARY) cout << " temporary\n"; } // //----< test file attribute extraction >----------------------- void main() { char filename[MAX_PATH]; DWORD attributes; cout << "\n Demonstrating Extraction of File Attributes " << "\n =============================================\n\n"; cout << " Enter filename: "; cin >> filename; attributes = GetFileAttributes(filename); if(attributes == 0xFFFFFFFF) { cout << " Can't find file " << filename << "\n\n"; return; } ShowAttributes(attributes); }