Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to change the folder attribute to RO
Message
 
 
To
04/02/2004 11:10:38
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00873653
Message ID:
00874094
Views:
17
Alan,

That code will destroy any other attributes that might be set on the file.

It's best to use bitor( GetFileAttributes(...), FILE_ATTRIBUTE_READONLY ) to add the readonly flag to the existing attributes.
#define FILE_ATTRIBUTE_READONLY             0x00000001  
#define FILE_ATTRIBUTE_HIDDEN               0x00000002  
#define FILE_ATTRIBUTE_SYSTEM               0x00000004  
#define FILE_ATTRIBUTE_DIRECTORY            0x00000010  
#define FILE_ATTRIBUTE_ARCHIVE              0x00000020  
#define FILE_ATTRIBUTE_ENCRYPTED            0x00000040  
#define FILE_ATTRIBUTE_NORMAL               0x00000080  
#define FILE_ATTRIBUTE_TEMPORARY            0x00000100  
#define FILE_ATTRIBUTE_SPARSE_FILE          0x00000200  
#define FILE_ATTRIBUTE_REPARSE_POINT        0x00000400  
#define FILE_ATTRIBUTE_COMPRESSED           0x00000800  
#define FILE_ATTRIBUTE_OFFLINE              0x00001000  
#define FILE_ATTRIBUTE_NOT_CONTENT_INDEXED  0x00002000  

declare integer SetFileAttributes in win32api ;
  String lpFileName,  ;    && file name
  integer dwFileAttributes && attributes

declare integer GetFileAttributes in win32api ;
  String lpFileName   && name of file or directory

* sets it read only

SetFileAttributes( "C:\isql.bat", bitor( GetFileAttributes( "C:\isql.bat" ), FILE_ATTRIBUTE_READONLY ) )

* unsets readonly

SetFileAttributes( "C:\isql.bat", bitand( GetFileAttributes( "C:\isql.bat" ), bitnot( FILE_ATTRIBUTE_READONLY ) ) )
>I think it might be easier changing the attributes of the files in a folder. The code below does this for C:\test folder.
>
>
>DECLARE INTEGER SetFileAttributes IN kernel32.dll;
>   STRING @ lpFileName,;
>   INTEGER dwFileAttributes
>
>#DEFINE FILE_ATTRIBUTE_NORMAL    0x0080
>#DEFINE FILE_ATTRIBUTE_READONLY  0x0001
>
>SET DEFAULT TO C:\test
>lnNumFiles = ADIR(FileList,'*.*')
>
>FOR t = 1 TO lnNumFiles
>   =SetFileAttributes(FileList[t,1], FILE_ATTRIBUTE_READONLY)
>ENDFOR
>
df (was a 10 time MVP)

df FoxPro website
FoxPro Wiki site online, editable knowledgebase
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform