感谢您使用微软产品。您可以使用FileSystemObject中的对象来读取或设定文件的属性,具体的方法您可以参考以下文档:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/jsproAttributes.asp?frame=true - 微软全球技术中心 VB技术支持本贴子仅供CSDN的用户作为参考信息使用。其内容不具备任何法律保障。您需要考虑到并承担使用此信息可能带来的风险。具体事项可参见使用条款 (http://www.csdn.net/microsoft/terms.shtm)。
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/jsproAttributes.asp?frame=true - 微软全球技术中心 VB技术支持本贴子仅供CSDN的用户作为参考信息使用。其内容不具备任何法律保障。您需要考虑到并承担使用此信息可能带来的风险。具体事项可参见使用条款 (http://www.csdn.net/microsoft/terms.shtm)。
ByRef 只读 As Boolean, _
ByRef 存档 As Boolean, _
ByRef 系统 As Boolean, _
ByRef 隐藏 As Boolean, _
ByRef 压缩 As Boolean) As Long
'获得文件属性 Dim rc As Long
rc = GetFileAttributes(mFileName)
If rc <> 1 Then
只读 = rc And FILE_ATTRIBUTE_READONLY
存档 = rc And FILE_ATTRIBUTE_ARCHIVE
系统 = rc And FILE_ATTRIBUTE_SYSTEM
隐藏 = rc And FILE_ATTRIBUTE_HIDDEN
压缩 = rc And FILE_ATTRIBUTE_COMPRESSED
AttribGet = 1
Else
MsgBox "请检查文件路径和" & vbCrLf & " 文件名是否正确!", vbCritical, "文件打开出错"
AttribGet = 0
End If
End FunctionPublic Function AttribSet(ByVal mFileName As String, _
ByVal 只读 As Boolean, _
ByVal 存档 As Boolean, _
ByVal 系统 As Boolean, _
ByVal 隐藏 As Boolean, _
ByVal 压缩 As Boolean) As Long
'获得文件属性 Dim rc As Long
Dim fa As Long
If 只读 Then fa = fa Or FILE_ATTRIBUTE_READONLY
If 存档 Then fa = fa Or FILE_ATTRIBUTE_ARCHIVE
If 系统 Then fa = fa Or FILE_ATTRIBUTE_SYSTEM
If 隐藏 Then fa = fa Or FILE_ATTRIBUTE_HIDDEN
If 压缩 Then fa = fa Or FILE_ATTRIBUTE_COMPRESSED
rc = GetFileAttributes(mFileName)
If rc <> 1 Then
AttribSet = 1
Else
MsgBox "请检查文件路径和" & vbCrLf & " 文件名是否正确!", vbCritical, "文件打开出错"
AttribSet = 0
End If
End Function
Public Function AttribSet(ByVal mFileName As String, _
ByVal 只读 As Boolean, _
ByVal 存档 As Boolean, _
ByVal 系统 As Boolean, _
ByVal 隐藏 As Boolean, _
ByVal 压缩 As Boolean) As Long
'获得文件属性 Dim rc As Long
Dim fa As Long
If 只读 Then fa = fa Or FILE_ATTRIBUTE_READONLY
If 存档 Then fa = fa Or FILE_ATTRIBUTE_ARCHIVE
If 系统 Then fa = fa Or FILE_ATTRIBUTE_SYSTEM
If 隐藏 Then fa = fa Or FILE_ATTRIBUTE_HIDDEN
If 压缩 Then fa = fa Or FILE_ATTRIBUTE_COMPRESSED
rc = setFileAttributes(mFileName,fa)
If rc <> 1 Then
AttribSet = 1
Else
MsgBox "请检查文件路径和" & vbCrLf & " 文件名是否正确!", vbCritical, "文件打开出错"
AttribSet = 0
End If
End Function
shell("c:\command/c dir/ad/s/b>dir.txt")
然后按dir.txt文件里的目录一个一个用dir("*")遍历,
然后kill("dir.txt")
有点麻烦。
我再像别的办法,
先看看这个。
MAIL;[email protected]
'**************************************************************
'*****GetAllFileName()*****
'Function: Get the file's name from a lot of grade dirctories
'Parametric: 1.strPath-----File path
' 2.FileList()--File's name's array
'Return Value: Boolean 1.True----Success; 2.False----Failure
'**************************************************************
Public Function GetAllFileName(ByVal DirPath As String, FileList() As String) As Boolean
Dim MyName As String
Dim MyPath As String
Dim strNewPath As String
Dim NewName As String
If (Right(DirPath, 1) <> "\") Then
MyPath = DirPath & "\"
Else
MyPath = DirPath
End If
MyName = Dir(MyPath, vbDirectory) ' Retrieve the first entry.
Do While MyName <> "" ' Start the loop.
' Ignore the current directory and the encompassing directory.
If MyName <> "." And MyName <> ".." Then
' Use bitwise comparison to make sure MyName is a directory.
If (GetAttr(MyPath & MyName) And vbDirectory) = vbDirectory Then
'Go on finding the file in the new Directory or folder
strNewPath = MyPath & MyName
If (GetAllFileName(strNewPath, FileList)) Then
NewName = Dir(MyPath, vbDirectory)
Do While (NewName <> MyName)
NewName = Dir
Loop
End If
Else
'Get the filename and insert the filename into the Array
ReDim Preserve FileList(index)
FileList(index) = MyPath & MyName
index = index + 1
End If ' it represents a directory.
End If
MyName = Dir ' Get next entry.
Loop
GetAllFileName = True
Exit Function
Err_GetFile:
MsgBox MyPath & Err.Description
GetAllFileName = False
End Function