So blenden Sie eine Datei aus / ein, ohne andere Attribute in C ++ unter Windows zu löschen
Ich möchte eine Datei in Windows in C ++ ein- und ausblenden, habe mir aber Sorgen gemacht, andere Attribute zu löschen (wie FILE_ATTRIBUTE_READONLY, FILE_ATTRIBUTE_ARCHIVE, ...).
Hier ist der aktuelle Code:
<code>//Hiding the file SetFileAttributes(path, FILE_ATTRIBUTE_HIDDEN); // Un-Hiding the file SetFileAttributes(path, FILE_ATTRIBUTE_NORMAL); </code>
Dies funktioniert gut für reguläre Dateien, aber wird durch das Ausblenden der Datei beispielsweise ein READONLY-Flag entfernt? Wird die Datei durch Ausblenden entfernt?
Wenn ja, hatte ich vor, so etwas zu machen:
<code>//Hiding the file int attr = GetFileAttributes(path); if ((attr | FILE_ATTRIBUTE_HIDDEN) == 0) { SetFileAttributes(path, attr & FILE_ATTRIBUTE_HIDDEN); } //Unhiding the file int attr = GetFileAttributes(path); if ((attr | FILE_ATTRIBUTE_HIDDEN) == FILE_ATTRIBUTE_HIDDEN) { SetFileAttributes(path, attr & FILE_ATTRIBUTE_HIDDEN); } </code>
Funktioniert das?