去除文件属性(使用SetFileAttributes API函数)

去除文件属性(使用SetFileAttributes API函数)

FILE_ATTRIBUTE_ARCHIVE 文件存档(备份或移动时会对文件做标记)。
FILE_ATTRIBUTE_ENCRYPTED 加密(对文件来说是内容加密,对目录来说是对将来新建的文件默认为加密属性),与此同时,如果还设置了FILE_ATTRIBUTE_SYSTEM属性,当前这个属性将无效。
FILE_ATTRIBUTE_HIDDEN 隐藏属性。
FILE_ATTRIBUTE_NORMAL 文件没有其他属性设置,此属性只能单独使用才合法。
FILE_ATTRIBUTE_NOT_CONTENT_INDEXED 不建立内容索引。
FILE_ATTRIBUTE_OFFLINE 脱机属性。文件内容暂时不可用。此属性被Remote Storage软件所用,不能任意更改。
FILE_ATTRIBUTE_READONLY 只读文件属性。应用程序不能写或删除。
FILE_ATTRIBUTE_SYSTEM 文件是系统文件或被操作系统互斥地使用。
FILE_ATTRIBUTE_TEMPORARY 临时文件,使用过程中尽量留在内存以保证存取速度。

 

 

FUNCTION ulong SetFileAttributes(ref string lpFileName,ulong dwFileAttributes) LIBRARY "kernel32.dll" ALIAS FOR "SetFileAttributesA",
请高手指点我一下SetFileAttributes函数如何运用,谢谢!!!

lpFileName 要设置属性的资料名 

dwFileAttributes 以FILE_ATTRIBUTE_为前缀的一个或多个常数 


定义没错了,那几个常数从0起头代进去试试
MSDN:
FILE_ATTRIBUTE_ARCHIVE The file is an archive file. Applications use this attribute to mark files for backup or removal. 
FILE_ATTRIBUTE_HIDDEN The file is hidden. It is not included in an ordinary directory listing. 
FILE_ATTRIBUTE_NORMAL The file has no other attributes set. This attribute is valid only if used alone. 
FILE_ATTRIBUTE_NOT_CONTENT_INDEXED The file will not be indexed by the content indexing service. 
FILE_ATTRIBUTE_OFFLINE The data of the file is not immediately available. This attribute indicates that the file data has been physically moved to offline storage. This attribute is used by Remote Storage, the hierarchical storage management software in Windows 2000. Applications should not arbitrarily change this attribute. 
FILE_ATTRIBUTE_READONLY The file is read-only. Applications can read the file but cannot write to it or delete it. 
FILE_ATTRIBUTE_SYSTEM The file is part of the operating system or is used exclusively by it. 
FILE_ATTRIBUTE_TEMPORARY The file is being used for temporary storage. File systems attempt to keep all of the data in memory for quicker access rather than flushing the data back to mass storage. A temporary file should be deleted by the application as soon as it is no longer needed. 


/*
Function boolean SetFileAttributesA(string lpFileName,ulong dwFileAttributes) LIBRARY "kernel32.dll"  
Function ulong GetFileAttributesA(string lpFileName) LIBRARY "kernel32.dll"
*/
ulong ll_FileAttributes
string is_filename = "" //资料路经及资料名.如"c:\File.txt"
string is_fileattributes ="R+"

ll_FileAttributes=GetFileAttributesA(is_FileName)

is_FileAttributes=Upper(is_FileAttributes)

IF Pos(is_FileAttributes,"R+")>0 and Mod(ll_FileAttributes,2)  <  1 THEN ll_FileAttributes += 1
IF Pos(is_FileAttributes,"R-")>0 and Mod(ll_FileAttributes,2)  >  0 THEN ll_FileAttributes -= 1

IF Pos(is_FileAttributes,"H+")>0 and Mod(ll_FileAttributes,4)  <  2 THEN ll_FileAttributes += 2
IF Pos(is_FileAttributes,"H-")>0 and Mod(ll_FileAttributes,4)  >  1 THEN ll_FileAttributes -= 2

IF Pos(is_FileAttributes,"S+")>0 and Mod(ll_FileAttributes,8)  <  4 THEN ll_FileAttributes += 4
IF Pos(is_FileAttributes,"S-")>0 and Mod(ll_FileAttributes,8)  >  3 THEN ll_FileAttributes -= 4

IF Pos(is_FileAttributes,"A+")>0 and Mod(ll_FileAttributes,64) < 32 THEN ll_FileAttributes +=32
IF Pos(is_FileAttributes,"A-")>0 and Mod(ll_FileAttributes,64) > 31 THEN ll_FileAttributes -=32

SetFileAttributesA(is_FileName,ll_FileAttributes)


//R+ : 设置只读属性
//R- : 去掉只读属性
//H+ : 设置隐含属性
//H- : 去掉隐含属性
//S+ : 设置系统属性
//S- : 去掉系统属性
//A+ : 设置存档属性
//A- : 去掉存档属性 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值