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::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


  • Qt Champions 2016

    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
    Thanks for your reply
    I dont think this will allow me to set the permissions on the folder though


  • Qt Champions 2016

    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


  • Qt Champions 2016

    @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
    Thanks for your help


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.