#include #include void getFileAttributes(const char* filename) { DWORD attributes = GetFileAttributesA(filename); if (attributes != INVALID_FILE_ATTRIBUTES) { if (attributes & FILE_ATTRIBUTE_READONLY) { printf("The file is read-only.\n"); } if (attributes & FILE_ATTRIBUTE_HIDDEN) { printf("The file is hidden.\n"); } if (attributes & FILE_ATTRIBUTE_SYSTEM) { printf("The file is a system file.\n"); } if (attributes & FILE_ATTRIBUTE_DIRECTORY) { printf("The file is a directory.\n"); } if (attributes & FILE_ATTRIBUTE_ARCHIVE) { printf("The file is archived.\n"); } } else { printf("Failed to get file attributes. Error code: %d\n", GetLastError()); } } void setFileAttributes(const char* filename, DWORD attributes) { if (!SetFileAttributesA(filename, attributes)) { printf("Failed to set file attributes. Error code: %d\n", GetLastError()); } else { printf("File attributes set successfully.\n"); } } int main() { const char* filename = "C:\\Users\\SEEDAGX\\source\\repos\\Attributes\\Attributes\\test.txt"; // 対象のファイルパスを指定してください // ファイル属性の取得 getFileAttributes(filename); // ファイル属性の設定例(読み取り専用属性を追加する) setFileAttributes(filename, FILE_ATTRIBUTE_READONLY); return 0; }