[Interest] Changing permissions in a dir
Bob Hood
bhood2 at comcast.net
Mon Mar 31 14:28:45 CEST 2014
On 3/31/2014 5:03 AM, Sensei wrote:
> First: the code won't work and stops after descending into the target
> directory... and I cannot figure out why!
You're going to need to set some additional flags on your call to entryInfoList():
QFileInfoList list = d.entryInfoList(filters,
QDir::Files|QDir::Dirs|QDir::NoDot|QDir::NoDotDot);
That should get the a proper listing of the entries in the target folder.
Next, your call to push the folder onto the stack is only pushing the folder's
parent, not the folder itself:
dirs.push(info.absolutePath());
This means that, if your target folder was X:\Temp, and you found a sub-folder
called X:\Temp\Bob, you'd be pushing "X:\Temp" onto your stack. Probably not
what you want. So you should change that line to instead be:
dirs.push(info.absoluteFilePath());
After making these changes, your example recursively processes a folder as
expected.
> Second: can I change permissions of a directory?
Well, under UN*X-based systems, the permission changing should work as you
expect with setPermissions() (assuming you have sufficient rights). Under
Windows, though, it probably won't. Windows uses a different beast in terms
of permissions (ACLs and such), so you may need to go with a Windows-specific
solution in your code. Look up "AllocateAndInitializeSid", "SetEntriesInAcl",
and "SetNamedSecurityInfo".
More information about the Interest
mailing list