当前位置: 代码迷 >> VBA >> 怎么通过vba获取一个目录下的所有文件夹名称、大小、文件夹中所有文档数量
  详细解决方案

怎么通过vba获取一个目录下的所有文件夹名称、大小、文件夹中所有文档数量

热度:7833   发布时间:2013-02-26 00:00:00.0
如何通过vba获取一个目录下的所有文件夹名称、大小、文件夹中所有文档数量?
如何通过vba获取一个目录下的所有文件夹名称、大小、文件夹中所有文档数量?
例如:
vb-vba1
              -1.txt
              -2.txt
    -vba2
              -3.txt
    -vba3

需要的结果是:
文件夹名称         文件夹大小     文件夹文档数量
vba1                                                             2
vba2                                                             1
vba3                                                             0


------解决方案--------------------------------------------------------
<hta>
<head>
<META HTTP-EQUIV= "pragma " CONTENT= "no-cache ">
<META HTTP-EQUIV= "Cache-Control " CONTENT= "no-cache, must-revalidate ">
<META HTTP-EQUIV= "expires " CONTENT= "0 ">
<title> 命名程序 </title>
</head>
<body scroll= "auto " style= "border:none; color:green; " bgcolor=black topmargin=0 leftmargin=0 rightmargin=0 bottommargin=0 >
<textarea id=show rows=10 style= "width:100%; "> </textarea>
<textarea id=dofile rows=20 style= "width:100%; " title=请在这输入处理文件的方法> function (path){

请在这输入处理文件的方法,其它不变。

} </textarea>

源文件夹 <input id= "sourcefolder " type=file> <br> <input type=button value=获取全部文件夹 onclick= "getallfolder(sourcefolder.value) ">

<input type=button value=处理所有文件 onclick= "doallfile() ">
<input type=button value=清除 onclick= "showtxt( '已清除所有定时 '); clearTimeout(fsotime) ">
<SCRIPT language= "javascript ">
<!--

var fso = new ActiveXObject( "Scripting.FileSystemObject ");
var runtime = 1;
var foldersarray;
var fsotime;
var nowi;
var fp;
var theno;
var mydofile;

function showtxt(txt)
{
show.focus();
show.value += txt + "\n ";
}

function reportError(msg,url,line)
{
alert( "当前页的脚本发生错误: \n\n信息: " + msg + "\n\n行: " + line);
return true;
}

window.onerror = reportError;

function getallfolder(path)
{
 if ( fso.folderExists(path) == false)
   {
showtxt( "出错啦!\n[ " + path + "] 文件夹不存在! ");
return false;
}

if(fso.DriveExists(path))
{
path += "\\ ";
}

mygetfolder(path);
}

function mygetfolder(path){//自己递归时没参数

if(path != undefined)
{
clearTimeout(fsotime);
fp = null;
nowi = -1;
theno = 1;
foldersarray = new Array(fso.getFolder(path).path);
showtxt( "开始获取文件夹...\n " + (theno++) + ": " + fso.getFolder(path).path);
}

try
{
if(fp == null)
  相关解决方案