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