Created
December 12, 2023 18:35
-
-
Save Sohamkadam333/48753fdad9b10145b9fe234e91d073ce to your computer and use it in GitHub Desktop.
Sets the attributes for a file or directory.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SetFileAttributes function is part of the Windows API and is used to set the attributes of a file or directory. Attributes include information such as whether the file is read-only, hidden, or system, among others. | |
#include <iostream> | |
#include <windows.h> | |
using namespace std; | |
int main() | |
{ | |
const wchar_t *filePath = L"E:\\newFile.txt"; | |
DWORD fileAttributes = FILE_ATTRIBUTE_READONLY; | |
if(SetFileAttributes(filePath,fileAttributes)) | |
{ | |
cout<<"File Attributes set successfully"<<endl; | |
} | |
else | |
{ | |
cout<<"File Attribute setting error, Error No : "<<GetLastError()<<endl; | |
} | |
system("PAUSE"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment