# how to make a folder non writable

• Hi
I have a need to make a folder non writable
I have made a QFile object and set the permissions to 0 but I am still able to perform a mkpath operation

``````		QFile file(dir.path());
QString s = file.fileName();
QFile::Permissions permissions = file.permissions();
QFile::Permissions oldPermissions = permissions;
permissions &= QFile::ExeGroup;
permissions &= QFile::WriteOwner;
permissions &= QFile::WriteUser;
permissions &= QFile::ExeUser;
permissions &= QFile::WriteGroup;
permissions &= QFile::WriteOther;
permissions &= QFile::ExeOther;
file.setPermissions(permissions);
``````

What is the correct way of doing this

Thanks

• HI
Are you sure QFile will do it with a folder ?
Maybe try
QFile::Permissions perm = QFileInfo( "c:/ACCESS_DENIED/" ).permissions();
Since it mention folder also.
Never tried it! so just suggestion.

• Hi
I dont think this will allow me to set the permissions on the folder though

• Hi
Yeah, after I posted ,
I realized that QFileInfo seems to have no setPermissions so
its back to QFile again. sorry.

Its under linux I assume ?

So the user the program runs under/as do have the permission to set permissions ?

• Actually this is running under Windows
Dont think I can do it using Qt tho

• @GrahamL
oh
and you did notice
extern Q_CORE_EXPORT int qt_ntfs_permission_lookup;

Well, if you trying to set the Read Only flag for the folder,
i think you are right that it wont work with Qt and you would have to resort to
SetFileAttributes
https://msdn.microsoft.com/en-us/library/aa365535.aspx

If that is the effect you want to get.

• OK