Skip to content

Instantly share code, notes, and snippets.

@Sohamkadam333
Created December 12, 2023 18:35
Show Gist options
  • Save Sohamkadam333/48753fdad9b10145b9fe234e91d073ce to your computer and use it in GitHub Desktop.
Save Sohamkadam333/48753fdad9b10145b9fe234e91d073ce to your computer and use it in GitHub Desktop.
Sets the attributes for a file or directory.
// 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