ottor

VB获取和修改文件属性

使用VB函数GetAttr()

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

使用 SetAttr (设定文件的属性)

Private Sub Command1_Click()
SetAttr "C:\Autoexec.Bat", 1 + 2 + 32
Print "C:\Autoexec.Bat 此文件被设定成 只读 & 隐藏 & 保存属性"
End Sub

属性值:
0 一般
1 只读
2 隐藏
4 系统
16 文件夹
32 保存属性
(好像也有vbXXX什么的常量值,或者从VS6的WinApi32.txt里找到常量,不用记数字那么麻烦)

PS:用COM Object FileSystemObject也可行。
发表于 2007-11-02 14:20  ottor_J2ME  阅读(2213)  评论(0编辑  收藏  举报
 

分类:

技术点:

相关文章:

  • 2021-12-16
  • 2021-12-08
  • 2022-01-15
  • 2022-01-23
  • 2021-12-24
  • 2022-02-21
  • 2022-02-23
猜你喜欢
  • 2021-09-06
  • 2022-02-15
  • 2021-07-11
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-18
相关资源
相似解决方案