VB如何改变文件属性

用VB对一些文件的属性进行改变如像.BAT中attrib一样最好给个代码本人谢谢了... 用VB对一些文件的属性进行改变 如像.BAT中attrib一样
最好给个代码 本人谢谢了
展开
 我来答
百度网友7aed2e5
2007-05-20 · TA获得超过1031个赞
知道小有建树答主
回答量:795
采纳率:0%
帮助的人:549万
展开全部
SetAttr

常数 值 描述
vbNormal 0 正常的(Dir 和 SetAttr 的缺省值)
vbReadOnly 1 只读的
vbHidden 2 隐藏的
vbSystem 4 系统文件
vbVolume 8 卷标
vbDirectory 16 目录或文件夹
vbArchive 32 文件自上一次备份后已经改变
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
摆渡浮桥
2007-05-20 · TA获得超过3631个赞
知道大有可为答主
回答量:1610
采纳率:100%
帮助的人:2353万
展开全部
Function ChangeFileAttributes(strPath As String, _
Optional lngSetAttr As FileAttribute, _
Optional lngRemoveAttr As FileAttribute, _
Optional blnRecursive As Boolean) As Boolean

' This function takes a directory path, a value specifying file
' attributes to be set, a value specifying file attributes to be
' removed, and a flag that indicates whether it should be called
' recursively. It returns True unless an error occurs.

Dim fsoSysObj As FileSystemObject
Dim fdrFolder As Folder
Dim fdrSubFolder As Folder
Dim filFile As File

' Return new FileSystemObject.
Set fsoSysObj = New FileSystemObject

On Error Resume Next
' Get folder.
Set fdrFolder = fsoSysObj.GetFolder(strPath)
If Err <> 0 Then
' Incorrect path.
ChangeFileAttributes = False
GoTo ChangeFileAttributes_End
End If
On Error GoTo 0

' If caller passed in attribute to set, set for all.
If lngSetAttr Then
For Each filFile In fdrFolder.Files
If Not (filFile.Attributes And lngSetAttr) Then
filFile.Attributes = filFile.Attributes Or lngSetAttr
End If
Next
End If

' If caller passed in attribute to remove, remove for all.
If lngRemoveAttr Then
For Each filFile In fdrFolder.Files
If (filFile.Attributes And lngRemoveAttr) Then
filFile.Attributes = filFile.Attributes - lngRemoveAttr
End If
Next
End If

' If caller has set blnRecursive argument to True, then call
' function recursively.
If blnRecursive Then
' Loop through subfolders.
For Each fdrSubFolder In fdrFolder.SubFolders
' Call function with subfolder path.
ChangeFileAttributes fdrSubFolder.Path, lngSetAttr, lngRemoveAttr, True
Next
End If
ChangeFileAttributes = True

ChangeFileAttributes_End:
Exit Function
End Function

'摘自 Microsoft MSDN.
本回答被提问者和网友采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式