Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. FILE_ATTRIBUTE_READONLY

FILE_ATTRIBUTE_READONLY

Scheduled Pinned Locked Moved C / C++ / MFC
question
10 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    elephantstar
    wrote on last edited by
    #1

    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!

    C D 2 Replies Last reply
    0
    • E elephantstar

      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!

      C Offline
      C Offline
      Chris Losinger
      wrote on last edited by
      #2

      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

      E 1 Reply Last reply
      0
      • E elephantstar

        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!

        D Offline
        D Offline
        David Crow
        wrote on last edited by
        #3

        elephantstar wrote: Instead it returns a value of 33. Which is a combination of FILE_ATTRIBUTE_ARCHIVE and FILE_ATTRIBUTE_READONLY.


        "Ideas are a dime a dozen. People who put them into action are priceless." - Unknown

        1 Reply Last reply
        0
        • C Chris Losinger

          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

          E Offline
          E Offline
          elephantstar
          wrote on last edited by
          #4

          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.

          N 1 Reply Last reply
          0
          • E elephantstar

            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.

            N Offline
            N Offline
            normanS
            wrote on last edited by
            #5

            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.

            E 2 Replies Last reply
            0
            • N normanS

              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.

              E Offline
              E Offline
              elephantstar
              wrote on last edited by
              #6

              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?

              1 Reply Last reply
              0
              • N normanS

                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.

                E Offline
                E Offline
                elephantstar
                wrote on last edited by
                #7

                Nevermind. It works. Thanks for all your help.

                N 1 Reply Last reply
                0
                • E elephantstar

                  Nevermind. It works. Thanks for all your help.

                  N Offline
                  N Offline
                  normanS
                  wrote on last edited by
                  #8

                  So, don't keep us all in suspense. What was the problem, and what was the solution?

                  E 1 Reply Last reply
                  0
                  • N normanS

                    So, don't keep us all in suspense. What was the problem, and what was the solution?

                    E Offline
                    E Offline
                    elephantstar
                    wrote on last edited by
                    #9

                    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.

                    N 1 Reply Last reply
                    0
                    • E elephantstar

                      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.

                      N Offline
                      N Offline
                      normanS
                      wrote on last edited by
                      #10

                      Ah, I guess we will have to watch out for the same problem! Thanks.

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups