送分贴,顺便问一下怎么得到某个目录下的文件总数...

gopark 2005-05-27 12:58:38
不要说要跑个循环哦..;-)
...全文
171 11 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
longjing_g 2005-05-27
  • 打赏
  • 举报
回复
getlength
longjing_g 2005-05-27
  • 打赏
  • 举报
回复
getlinght
lzhiqiu 2005-05-27
  • 打赏
  • 举报
回复
System.IO.Directory.GetFiles("c:\winnt").GetLength(0)

只能得到当前目录下面的文件数.如果要包含子目录下面的文件则需要用到循环.
tl_pear 2005-05-27
  • 打赏
  • 举报
回复
得到某个目录下的文件总数:
MsgBox(Directory.GetFiles("文件路径").Length)
得到某个目录下的文件和子目录总数:
MsgBox(Directory.GetFileSystemEntries("文件路径").Length)

注:包括了隐藏的文件或子目录!


gopark 2005-05-27
  • 打赏
  • 举报
回复
真的只有循环啊,郁闷啊..
就没有什么方法,属性一类的?
真是奇怪了..
haoztao 2005-05-27
  • 打赏
  • 举报
回复
当然要循环啦,呵呵
private void InitialTreeView()
{
//将驱动器字符串数组设为空
string[] drivers=null;
//检索此计算机上逻辑驱动器的名称
drivers=Directory.GetLogicalDrives();
int i=0;

//初始化每一个逻辑驱动器
while ( i<drivers.GetLength(0))
{
this.treeView1.Nodes.Add(new TreeNode(drivers[i],1,1));
string path=drivers[i];
string[] dirs=null;
try
{
//获得指定驱动器中第一级目录的名称
dirs=Directory.GetDirectories(path);
}
catch (Exception error)
{
//错误处理为空,即忽略
MessageBox.Show(error.Message);
}
if (dirs!=null)
{
//为每一个代表驱动器的根节点添加子节点
for (int j=0;j<dirs.Length;j++)
{
//获得节点的去掉路径后的目录名
TreeNode node = new TreeNode(dirs[j].ToString().Substring(dirs[j].ToString().LastIndexOf("\\")+1));
//设置不选定状态下的图标
node.ImageIndex =2;
//设置打开状态下的图标
node.SelectedImageIndex =0;
//添加节点
this.treeView1.Nodes[i].Nodes.Add(node);
}
}
//继续下一个循环
i++;
}

}
windlyc 2005-05-27
  • 打赏
  • 举报
回复
dim pInt as integer
Private Function StatFilecount(ByVal pDirInfo As System.IO.DirectoryInfo) As Integer
Dim pDirectinfo As System.IO.DirectoryInfo
StatFilecount = StatFilecount + pDirInfo.GetFiles.Length
Dim pSysinfo As System.IO.FileSystemInfo() = pDirInfo.GetDirectories()

Dim pstr As String
For Each pDirectinfo In pSysinfo
Console.Write(pDirectinfo.Name & "|")
StatFilecount(pDirectinfo)
Next
pInt = pInt + StatFilecount
End Function
这样行吗?效率可能不高!
miaojx 2005-05-27
  • 打赏
  • 举报
回复
用循环,就用循环
fengfangfang 2005-05-27
  • 打赏
  • 举报
回复
用Directory的GetFileSystemEntries
fengfangfang 2005-05-27
  • 打赏
  • 举报
回复
接分 帮你想想
caojinrong 2005-05-27
  • 打赏
  • 举报
回复
递归

16,722

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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