VB文件浏览器示例源码VB对文件属性更改,建立一个文本浏览器。窗体上放置驱动器列表框、目录列表框、文件列表框和复选框控件。该实例源码可对文件的属性进行更改。
核心代码:
Attribute VB_Name = "Form1" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute VB_PredeclaredId = True Attribute VB_Exposed = False Private Sub Command1_Click() Unload Me End Sub Private Sub Dir1_Change() ChDir Dir1.Path '改变当前目录 File1.Path = Dir1.Path '改变目录列表框的路径 ShowAttr Dir1.Path '设置属性复选框组 End Sub Private Sub Drive1_Change() ChDrive Drive1.Drive '改变当前驱动器 Dir1.Path = Drive1.Drive '改变文件列表框的路径 Call ClearAttr '设置属性复选框组 End Sub Private Sub File1_Click() ShowAttr File1.FileName '设置属性复选框组 End Sub Private Sub Form_Load() Drive1.Drive = "d:\" File1.Pattern = "*.*" End Sub Private Sub ClearAttr() Dim I As Integer For I = 0 To 5 '将Check1(0)~Check1(5)复选框清空 Check1(I).Value = 0 Next I End Sub Private Sub ShowAttr(ByVal sPath As String) Dim iAttr As Integer '存储文件的属性值 Call ClearAttr '调用复选框清空子程序 iAttr = GetAttr(sPath) '获取文件的属性 If iAttr And vbNormal Then '判断是否为普通文件 Check1(0).Value = Checked '是则普通复选框选中 End If If iAttr And vbReadOnly Then '判断是否为只读文件 Check1(1).Value = Checked '是则只读复选框选中 End If If iAttr And vbDirectory Then '判断是否为目录 Check1(2).Value = Checked '是则文件夹复选框选中 End If If iAttr And vbSystem Then '判断是否为系统文件 Check1(3).Value = Checked '是则系统复选框选中 End If If iAttr And vbArchive Then '判断是否为存档文件 Check1(4).Value = Checked '是则存档复选框选中 End If If iAttr And vbHidden Then '判断是否为隐藏文件 Check1(5).Value = Checked '是则隐藏复选框选中 End If End Sub
分享地址
- 标签: 文件浏览器