目录长度不起作用 [英] Directory length not working

查看:75
本文介绍了目录长度不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这可能是一个愚蠢的问题,但我试图找出文件夹中有多少文件,一个minuite告诉我0,下一次它告诉我1那时根本就没有文件。



我甚至在我的文档中创建了一个名为H的新文件夹,其中根本没有任何内容,它仍然会返回1项。有人请解释这个,甚至自己尝试,它会伤害我的脑袋



  int  i = Directory.GetFiles( @  C:\ Users \William \Documents\H\\ \\)长度; 
MessageBox.Show(Convert.ToString(i));

解决方案

尝试

< pre lang =cs> if (Directory.Exists(path))
{
/ / 此路径是一个目录
int i = Directory.GetFiles(path )。长度;
MessageBox.Show(Convert.ToString(i));

}


if Directory.GetFiles 返回一个长度,at那个时候可能有一个文件。那么为什么不在运行时调试和检查文件详细信息或显示带文件名的消息?

如下所示

 < span class =code-keyword> string  [] files = Directory.GetFiles( @  C: \Users\William\Documents\H\); 
MessageBox.Show( string .Format( 文件计数:{0}和文件:{1},files.Length, string .Join( ,files)));


This may be a stupid question but im trying to find out how many files are in a folder and one minuite its telling me 0 and the next time its telling me 1 when there is simply no files there.

I even made a new folder called H in my documents with nothing in there at all and its still coming back 1 item. someone please explain this or even try it yourself, its hurting my head

int i = Directory.GetFiles(@"C:\Users\William\Documents\H\").Length;
            MessageBox.Show(Convert.ToString(i));

解决方案

Try

if(Directory.Exists(path))
            {
                // This path is a directory
              int i = Directory.GetFiles(path).Length;
              MessageBox.Show(Convert.ToString(i));
                   
            }


if Directory.GetFiles return one as length, at that time there may be a file. So why don't you debug and check the file details at run time or show message with file names?
do as below

string[] files= Directory.GetFiles(@"C:\Users\William\Documents\H\");
MessageBox.Show(string.Format("File Count :{0} and Files :{1}", files.Length, string.Join(",",  files)));


这篇关于目录长度不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆