VB获取和更改文件属性

VB获取和更改文件属性

摘自网络供自己备查!

Private Declare Function SetFileAttributes Lib "kernel32" Alias "SetFileAttributesA" (ByVal lpFileName As String, ByVal dwFileAttributes As Long) As Long
Private Declare Function GetFileAttributes Lib "kernel32" Alias "GetFileAttributesA" (ByVal lpFileName As String) As Long
Private Const FILE_ATTRIBUTE_ARCHIVE = &H20
Private Const FILE_ATTRIBUTE_COMPRESSED = &H800
Private Const FILE_ATTRIBUTE_DIRECTORY = &H10
Private Const FILE_ATTRIBUTE_HIDDEN = &H2
Private Const FILE_ATTRIBUTE_NORMAL = &H80
Private Const FILE_ATTRIBUTE_READONLY = &H1
Private Const FILE_ATTRIBUTE_SYSTEM = &H4
Private Const FILE_ATTRIBUTE_TEMPORARY = &H100

修改:
Private Sub Command1_Click()
SetFileAttributes "C:\1.txt", 1
End Sub

Private Sub Command2_Click()
SetFileAttributes "C:\1.txt", 2
End Sub

判断:

Private Sub Command1_Click()
Print GetAttr("C:\Autoexec.Bat")
If GetFileAttributes("C:\1.Bat") And 1 Then Print "此文件只读"
If GetFileAttributes("C:\1.Bat") And 2 Then Print "此文件隐藏"
If GetFileAttributes("C:\1.Bat") And 4 Then Print "此文件为系统文件"
If GetFileAttributes("C:\1.Bat") And 16 Then Print "此文件为文件夹"
If GetFileAttributes("C:\1.Bat") And 32 Then Print "此文件为保存属性"
End Sub

其中属性值:
0 一般
1 只读
2 隐藏
4 系统
16 文件夹
32 保存属性

要加多个属性的话可以写成: SetFileAttributes "C:\1.txt", 1 + 2 + 32

Cacls.exe 命令行下修改文件访问控制权限

不多写了自己慢慢去研究吧!!

嘎嘎

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值