计算net framework 2.0上的文件 [英] count files on net framework 2.0

查看:69
本文介绍了计算net framework 2.0上的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为net framework 4.5创建了这个代码,是否可以在Windows 2000上使用框架版本2.0?如果不是如何做同样的事情(计算扩展名为.dat且大小最大为300kb的文件)?

I have this code created for net framework 4.5, is it possible to work with framework version 2.0 on windows 2000? If not how to do same things (count files with extension of .dat with size of maximum 300kb)?


public void Form1_Load(object sender, EventArgs e)
       {

           DirectoryInfo dir = new DirectoryInfo(@"C:/a");
           int fileCount = dir.GetFiles("*.dat").Where(m => (m.Length / 1024) > 285).Count();

textBox1.Text = fileCount.ToString();

推荐答案

这只是基于Linq的你在哪里不能使用所以使用循环代替



It's only the Linq-based Where you can't use so use a loop instead

DirectoryInfo dir = new DirectoryInfo(@"C:/a");
int fileCount = 0;
foreach (FileInfo file in dir.GetFiles("*.dat"))
{
    if ((file.Length / 1024) > 258)
    {
        fileCount++;
    }

}


这篇关于计算net framework 2.0上的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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