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. How to chage attributes for a directory?

How to chage attributes for a directory?

Scheduled Pinned Locked Moved C / C++ / MFC
helptutorialquestion
8 Posts 2 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.
  • H Offline
    H Offline
    hfrmobile
    wrote on last edited by
    #1

    Changing file attributes for a file is no problem (e.g. using the SetFileAttributes() function). Is there an equivalent for doing this for a directory? Thanks in advance, hfr :sigh: PS: if using SetFileAttributes() for a directory I get a HRESULT of 2 which means: file not found

    D 1 Reply Last reply
    0
    • H hfrmobile

      Changing file attributes for a file is no problem (e.g. using the SetFileAttributes() function). Is there an equivalent for doing this for a directory? Thanks in advance, hfr :sigh: PS: if using SetFileAttributes() for a directory I get a HRESULT of 2 which means: file not found

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

      :confused: This works for me:

      if (! SetFileAttributes("c:\\ResOrg", FILE_ATTRIBUTE_READONLY))
      {
      DWORD dwError = GetLastError();
      }


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

      H 1 Reply Last reply
      0
      • D David Crow

        :confused: This works for me:

        if (! SetFileAttributes("c:\\ResOrg", FILE_ATTRIBUTE_READONLY))
        {
        DWORD dwError = GetLastError();
        }


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

        H Offline
        H Offline
        hfrmobile
        wrote on last edited by
        #3

        Hi thanks for your reply! Sorry, I was a bit inaccurately... I am using RAPI version of SetFileAttributes() --> CeSetFileAttributes() because I need to do this on a remote device (on a Pocket PC running Windows CE) It seems that there is a difference between SetFileAttributes() and CeSetFileAttributes(). CeSetFileAttributes() works fine for files but not for directories. The only thing I have found about this issue is that the .NET Compact Framework does not support changing attributes on directories... (files are supported). Since the project is written in VC++ this should not matter... CeSetFileAttributes() always returns false and CeGetLastError() returns 0x2 (file not found...) Any idea why CeSetFileAttributes() does not work for directories? thx :doh:

        D 1 Reply Last reply
        0
        • H hfrmobile

          Hi thanks for your reply! Sorry, I was a bit inaccurately... I am using RAPI version of SetFileAttributes() --> CeSetFileAttributes() because I need to do this on a remote device (on a Pocket PC running Windows CE) It seems that there is a difference between SetFileAttributes() and CeSetFileAttributes(). CeSetFileAttributes() works fine for files but not for directories. The only thing I have found about this issue is that the .NET Compact Framework does not support changing attributes on directories... (files are supported). Since the project is written in VC++ this should not matter... CeSetFileAttributes() always returns false and CeGetLastError() returns 0x2 (file not found...) Any idea why CeSetFileAttributes() does not work for directories? thx :doh:

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

          rubicon_hfr wrote: Any idea why CeSetFileAttributes() does not work for directories? No. I've no experience with CE or the .Net framework. What folder attribute are you wanting to alter? If I am reading the documentation correctly, it states that an application cannot change the attributes of a directory in the RAM file system. Does that apply to your situation?


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

          H 1 Reply Last reply
          0
          • D David Crow

            rubicon_hfr wrote: Any idea why CeSetFileAttributes() does not work for directories? No. I've no experience with CE or the .Net framework. What folder attribute are you wanting to alter? If I am reading the documentation correctly, it states that an application cannot change the attributes of a directory in the RAM file system. Does that apply to your situation?


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

            H Offline
            H Offline
            hfrmobile
            wrote on last edited by
            #5

            I assume you mean ROM, not RAM? Of course I do not try to alter attributes of a directory which is located in ROM. In this case I'll expect a "access denied" error... I'd like to change directory's attributes which are located in RAM or on a storage card. I can delete or rename the directories but I cannot change the "r" or "h" attribute...

            D 1 Reply Last reply
            0
            • H hfrmobile

              I assume you mean ROM, not RAM? Of course I do not try to alter attributes of a directory which is located in ROM. In this case I'll expect a "access denied" error... I'd like to change directory's attributes which are located in RAM or on a storage card. I can delete or rename the directories but I cannot change the "r" or "h" attribute...

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

              rubicon_hfr wrote: I assume you mean ROM, not RAM? No, RAM was the intended word. See here.


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

              H 1 Reply Last reply
              0
              • D David Crow

                rubicon_hfr wrote: I assume you mean ROM, not RAM? No, RAM was the intended word. See here.


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

                H Offline
                H Offline
                hfrmobile
                wrote on last edited by
                #7

                Very interesting... thx! This code (see comments) demonstrates what happens: CeRapiInit(); // "\\CF-Card\\Temp" // "\\SD-MMCard\\Temp" // "\\Temp\\Test" CString strFileName = "\\SD-MMCard\\Temp"; wchar_t wcFileName[256]; mbstowcs(wcFileName, strFileName, strFileName.GetLength()+1); DWORD dwAttributes = CeGetFileAttributes(wcFileName); // works always HRESULT hr = CeGetLastError(); dwAttributes |= FILE_ATTRIBUTE_READONLY; // hr = 0x00000002 "The system cannot find the file specified." if dir is in RAM // hr = 0x00000005 "Access is denied." if dir is on storage card // this problems only occur using RAPI CeSetFileAttributes(wcFileName, dwAttributes); hr = CeGetLastError(); CeRapiUninit(); RAM: "The system cannot find the file specified." (ok, since MSDN says it is not supported Storage Cards: "Access is denied." (also not supported?:(( )

                H 1 Reply Last reply
                0
                • H hfrmobile

                  Very interesting... thx! This code (see comments) demonstrates what happens: CeRapiInit(); // "\\CF-Card\\Temp" // "\\SD-MMCard\\Temp" // "\\Temp\\Test" CString strFileName = "\\SD-MMCard\\Temp"; wchar_t wcFileName[256]; mbstowcs(wcFileName, strFileName, strFileName.GetLength()+1); DWORD dwAttributes = CeGetFileAttributes(wcFileName); // works always HRESULT hr = CeGetLastError(); dwAttributes |= FILE_ATTRIBUTE_READONLY; // hr = 0x00000002 "The system cannot find the file specified." if dir is in RAM // hr = 0x00000005 "Access is denied." if dir is on storage card // this problems only occur using RAPI CeSetFileAttributes(wcFileName, dwAttributes); hr = CeGetLastError(); CeRapiUninit(); RAM: "The system cannot find the file specified." (ok, since MSDN says it is not supported Storage Cards: "Access is denied." (also not supported?:(( )

                  H Offline
                  H Offline
                  hfrmobile
                  wrote on last edited by
                  #8

                  FYI: Conclusion - setting file attributes for directories I tried something and here are the results: CeGetFileAttributes() Worked for all devices. CeSetFileAttributes() Not worked on a PPC2002 device (Pocket PC) Worked on a WM2003 device (Smartphone) So it seems that this is only supported for devices using WM2003 or higner...

                  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