你能行!?

lwz2001 2001-12-02 08:57:02
各为,如何得到一个目录的所有文件的文件名,文件长度,还有属性?
...全文
63 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
DeityFox 2001-12-02
  • 打赏
  • 举报
回复
直接条用windows属性窗口

Public Type SHELLEXECUTEINFO
cbSize As Long
fMask As Long
hwnd As Long
lpVerb As String
lpFile As String
lpParameters As String
lpDirectory As String
nShow As Long
hInstApp As Long
' Optional fields
lpIDList As Long
lpClass As String
hkeyClass As Long
dwHotKey As Long
hIcon As Long
hProcess As Long
End Type
Public Const SEE_MASK_INVOKEIDLIST = &HC
Public Const SEE_MASK_NOCLOSEPROCESS = &H40
Public Const SEE_MASK_FLAG_NO_UI = &H400
Public Declare Function ShellExecuteEX Lib "shell32.dll" Alias "ShellExecuteEX"
(SEI as SHELLEXECUTEINFO) as Long

'定义子程序
Public sub showP(filename$,ownd as Long)
dim sei as SHELLEXECUTEINFO
dim r as long
with sei
.cbsize=len(sei)
.fmask=&HC or &H40 or &H400
.hwnd=ownd
.lpverb="properties"
.lpfile=filename
.lpparameters=vbnullchar
.lpDirectory=vbnullchar
.nshow=0
.hinstapp=0
.lpdlist=0
end with
r=shellexecuteex(sei)
end sub

现在你可以在程序中用 showp “c:\command.com",me.hwnd 来条用咯

DeityFox 2001-12-02
  • 打赏
  • 举报
回复
取得某个目录底下所有文件大小总和


含目录底下的子目录,求得其所有文件大小之总和
其第二个叁数的目的是起始Static型态的totbyte, 呼叫它时,请不要传叁数进去


Private Sub Command1_Click()
Dim tot As Long
tot = GetDirTotalByte("c:\tools\")
Debug.Print tot
End Sub
Private Function GetDirTotalByte(CurrentPath As String, Optional i As Long) As Long
Static totbyte As Long
Dim nI As Integer, nDirectory As Integer
Dim sFileName As String, sDirectoryList() As String
'Initial totbyte, if it is not the Recursive call the function
If i <> 1 Then
totbyte = 0
End If
'First list all normal files in this directory
sFileName = Dir(CurrentPath, vbNormal + vbHidden + vbReadOnly + vbSystem + vbArchive)
Do While sFileName <> ""
totbyte = totbyte + FileLen(CurrentPath + sFileName)
sFileName = Dir
Loop
'Next build temporary list of subdirectories
sFileName = Dir(CurrentPath, vbDirectory)
Do While sFileName <> ""
'Ignore current and parent directories
If sFileName <> "." And sFileName <> ".." Then
'Ignore nondirectories
If GetAttr(CurrentPath & sFileName) _
And vbDirectory Then
nDirectory = nDirectory + 1
ReDim Preserve sDirectoryList(nDirectory)
sDirectoryList(nDirectory) = CurrentPath & sFileName
End If
End If
sFileName = Dir
Loop
'Recursively process each directory
For nI = 1 To nDirectory
GetDirTotalByte sDirectoryList(nI) & "\", 1
Next nI
GetDirTotalByte = totbyte
End Function

koenig 2001-12-02
  • 打赏
  • 举报
回复
这个这个,你打开WINDOWS的资源管理器不就都有了吗:)
dsclub 2001-12-02
  • 打赏
  • 举报
回复


getfilesize
lwz2001 2001-12-02
  • 打赏
  • 举报
回复
请你留几句吧

7,763

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧