FILE_ATTRIBUTE_READONLY
-
I'm trying to upload a file to its designated location. If the file already exists and is read-only it doesn't allow me to overwrite it. Before overwriting the file, I first check to see if it's READ-ONLY by calling GetFileAttributes(). Then I reset the attribute from read-only to normal. Somehow it doesn't return FILE_ATTRIBUTE_READONLY even when it's a read-only file. Instead it returns a value of 33. What does that value correspond to? And why is it that I can't remove the READ-ONLY attribute so that I can overwrite the file? DWORD dwAttr = GetFileAttributes(filename); if(dwAttr == FILE_ATTRIBUTE_NORMAL) SetFileAttributes(filename, FILE_ATTRIBUTE_NORMAL); CopyFile(source, dest, FALSE); Thanks!
-
I'm trying to upload a file to its designated location. If the file already exists and is read-only it doesn't allow me to overwrite it. Before overwriting the file, I first check to see if it's READ-ONLY by calling GetFileAttributes(). Then I reset the attribute from read-only to normal. Somehow it doesn't return FILE_ATTRIBUTE_READONLY even when it's a read-only file. Instead it returns a value of 33. What does that value correspond to? And why is it that I can't remove the READ-ONLY attribute so that I can overwrite the file? DWORD dwAttr = GetFileAttributes(filename); if(dwAttr == FILE_ATTRIBUTE_NORMAL) SetFileAttributes(filename, FILE_ATTRIBUTE_NORMAL); CopyFile(source, dest, FALSE); Thanks!
try : if ((dwAttr & (FILE_ATTRIBUTE_READONLY)) != 0) { ... } the return value from GetFileAttributes can contain multiple values (it's a bit mask). Cleek | Image Toolkits | Thumbnail maker
-
I'm trying to upload a file to its designated location. If the file already exists and is read-only it doesn't allow me to overwrite it. Before overwriting the file, I first check to see if it's READ-ONLY by calling GetFileAttributes(). Then I reset the attribute from read-only to normal. Somehow it doesn't return FILE_ATTRIBUTE_READONLY even when it's a read-only file. Instead it returns a value of 33. What does that value correspond to? And why is it that I can't remove the READ-ONLY attribute so that I can overwrite the file? DWORD dwAttr = GetFileAttributes(filename); if(dwAttr == FILE_ATTRIBUTE_NORMAL) SetFileAttributes(filename, FILE_ATTRIBUTE_NORMAL); CopyFile(source, dest, FALSE); Thanks!
elephantstar wrote: Instead it returns a value of 33. Which is a combination of
FILE_ATTRIBUTE_ARCHIVE
andFILE_ATTRIBUTE_READONLY
.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
-
try : if ((dwAttr & (FILE_ATTRIBUTE_READONLY)) != 0) { ... } the return value from GetFileAttributes can contain multiple values (it's a bit mask). Cleek | Image Toolkits | Thumbnail maker
So that worked but how can I remove the read-only attribute? I called SetFileAttributes(filename, FILE_ATTRIBUTE_NORMAL) but that didn't do the trick.
-
So that worked but how can I remove the read-only attribute? I called SetFileAttributes(filename, FILE_ATTRIBUTE_NORMAL) but that didn't do the trick.
-
Could be that you don't have the necessary permissions / authority to change the attribute. Look at the value returned by SetFileAttributes - that may give you an idea why the call did not do what you expected.
I am the administrator of my machine so permissions shouldn't be a problem. The SetFileAttributes(filename, FILE_ATTRIBUTE_NORMAL) returns 0. Am I missing something?
-
Could be that you don't have the necessary permissions / authority to change the attribute. Look at the value returned by SetFileAttributes - that may give you an idea why the call did not do what you expected.
Nevermind. It works. Thanks for all your help.
-
Nevermind. It works. Thanks for all your help.
-
Sorry...it was just my stupidity in changing the wrong file. Instead of changing the destination file's attributes, I changed the source file's.
-
Sorry...it was just my stupidity in changing the wrong file. Instead of changing the destination file's attributes, I changed the source file's.