
VB如何改变文件属性
展开全部
SetAttr
常数 值 描述
vbNormal 0 正常的(Dir 和 SetAttr 的缺省值)
vbReadOnly 1 只读的
vbHidden 2 隐藏的
vbSystem 4 系统文件
vbVolume 8 卷标
vbDirectory 16 目录或文件夹
vbArchive 32 文件自上一次备份后已经改变
常数 值 描述
vbNormal 0 正常的(Dir 和 SetAttr 的缺省值)
vbReadOnly 1 只读的
vbHidden 2 隐藏的
vbSystem 4 系统文件
vbVolume 8 卷标
vbDirectory 16 目录或文件夹
vbArchive 32 文件自上一次备份后已经改变
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
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.
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.
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询