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 operationQFile file(dir.path()); QString s = file.fileName(); QFile::Permissions permissions = file.permissions(); QFile::Permissions oldPermissions = permissions; permissions &= QFile::ExeGroup; permissions &= QFile::ReadOwner; permissions &= QFile::WriteOwner; permissions &= QFile::ReadUser; permissions &= QFile::WriteUser; permissions &= QFile::ExeUser; permissions &= QFile::ReadGroup; permissions &= QFile::WriteGroup; permissions &= QFile::ReadOther; 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
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 ?
-
@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.aspxIf that is the effect you want to get.