⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 m62.htm

📁 vb教程 vb教程 vb教程 vb教程 vb教程 vb教程 vb教程 vb教程 vb教程 vb教程 vb教程
💻 HTM
字号:
<html>
<head>
<title>VB教程</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
 
</head>
<p align="center"><script src="../../1.js"></script></a>

<body bgcolor="#ffffff" leftmargin="5" topmargin="1" marginheight="5" marginwidth="5">
<div align=center> 
  <table border=0 cellpadding=0 cellspacing=0 width=680 align="center">
    <tbody> 
     
    <tr> 
      <td bgcolor=#000000 height=9> 
        <div align=center class=H1>    <font color="#FFFFFF">取得某个目录底下所有档案大小总和</font> </font> </font></div>
      </td>
    </tr>
    <tr valign=top> 
      <td class=H1 height=76> 
        <p align="left">  <br>
           </font> 含目录底下的子目录,求得其所有档案大小之总和<br>
          其第二个参数的目的是起始Static型态的totbyte, 呼叫它时,请不要传参数进去<br>
          </font></span><br>
        </p>
        <table border=0 width="681">
          <tbody> 
          <tr> 
            <td> <font color="#000000" class="unnamed1">Private Sub Command1_Click()<br>
              Dim tot As Long<br>
              tot = GetDirTotalByte("c:\tools\")<br>
              Debug.Print tot<br>
              End Sub<br>
              Private Function GetDirTotalByte(CurrentPath As String, Optional 
              i As Long) As Long<br>
              Static totbyte As Long<br>
              Dim nI As Integer, nDirectory As Integer<br>
              Dim sFileName As String, sDirectoryList() As String<br>
              'Initial totbyte, if it is not the Recursive call the function<br>
              If i &lt;&gt; 1 Then<br>
              totbyte = 0<br>
              End If<br>
              'First list all normal files in this directory<br>
              sFileName = Dir(CurrentPath, vbNormal + vbHidden + vbReadOnly + 
              vbSystem + vbArchive)<br>
              Do While sFileName &lt;&gt; ""<br>
              totbyte = totbyte + FileLen(CurrentPath + sFileName)<br>
              sFileName = Dir<br>
              Loop<br>
              'Next build temporary list of subdirectories<br>
              sFileName = Dir(CurrentPath, vbDirectory)<br>
              Do While sFileName &lt;&gt; ""<br>
              'Ignore current and parent directories<br>
              If sFileName &lt;&gt; "." And sFileName &lt;&gt; ".." Then<br>
              'Ignore nondirectories<br>
              If GetAttr(CurrentPath &amp; sFileName) _<br>
              And vbDirectory Then<br>
              nDirectory = nDirectory + 1<br>
              ReDim Preserve sDirectoryList(nDirectory)<br>
              sDirectoryList(nDirectory) = CurrentPath &amp; sFileName<br>
              End If<br>
              End If<br>
              sFileName = Dir<br>
              Loop<br>
              'Recursively process each directory<br>
              For nI = 1 To nDirectory<br>
              GetDirTotalByte sDirectoryList(nI) &amp; "\", 1<br>
              Next nI<br>
              GetDirTotalByte = totbyte<br>
              End Function</font><br>
            </td>
          </tr>
          </tbody>
        </table>
         
  </table>
</div>
<p align="center"><a href="../../pian/vb.htm">回首页</a>
<p align="center"><script src="../../2.js"></script></a>
</body>
</html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -