Incorrect QFileInfo permissions for user desktop on vista 64
Asked Answered
S

3

0

I am using the following code to determine if I can write to a specific directory using QFileInfo:

QFileInfo dinfo(dirname);
if (dinfo.exists())
  valid = dinfo.isWritable()

Unfortunately, when I pass in the path of the current user's desktop on Vista 64:

C:\Users\USERNAME\Desktop

QFileInfo::isWritable() returns false. However, if I pass it another directory (say C:\Temp) it returns true. I requested the directory permissions from the QFileInfo object which were 5555 (not writable by anyone). This code works as expected on other platforms including Windows XP. Anybody have any ideas as to what might be going on here.

As a point of reference, if I remove the check I can actually save the file to that location without a problem.

Schluter answered 6/7, 2009 at 23:1 Comment(0)
S
3

So, after a bit of digging through the Task Tracker at Qt, I discovered that QFileInfo::isWritable() is only valid for use on files and not directories. By changing the code to ask if I could create the file of interest instead of asking if the directory is writable, I was able to achieve the desired outcome:

QDir dir(dirname);
if (dir.exists())
{
  QFileInfo finfo(dir.absoluteFilePath(fname));
  valid = finfo.isWritable();
} 

Thanks.

Schluter answered 7/7, 2009 at 21:19 Comment(0)
P
0

I'm making a very wild guess here, but have you checked to see if it is a link, shortcut, alias, or other psuedo-folder? It seems possible to me that you are getting the permissions of a hard-coded symlink, which isn't writable, instead of the permissions of the item it is pointing to.

From the isSymLink() documentation (bold added by me):

On Unix (including Mac OS X), opening a symlink effectively opens the link's target. On Windows, it opens the .lnk file itself.

So I would check the results of isSymLink(), and if necessary get the real target from symLinkTarget() (and see the documentation for the last; the target may or may not actually exist).

Poulter answered 7/7, 2009 at 1:36 Comment(0)
I
0

The directory "C:\Users\USERNAME\Desktop" is by default Read Only on Windows Vista. This doesn't mean that you can't write files to the folder. This mean that you can not adjust the directory itself (name change ect.).

Irrefragable answered 7/7, 2009 at 8:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.