我有一段代码,是为了判断两个文件的大小,
System.IO.FileInfo info = new System.IO.FileInfo("Start.exe");
System.IO.FileInfo info1 = new System.IO.FileInfo("data\\texts_us.tbl"); if (info.Length.ToString() == "4391424" && info1.Length.ToString() == "46371")
{
}
else
{ }
上面的写法是正常,现在问题是我想增加两个,就是判断四个文件的大小,请问要怎么写了。
System.IO.FileInfo info = new System.IO.FileInfo("Start.exe");
System.IO.FileInfo info1 = new System.IO.FileInfo("data\\texts_us.tbl"); if (info.Length.ToString() == "4391424" && info1.Length.ToString() == "46371")
{
}
else
{ }
上面的写法是正常,现在问题是我想增加两个,就是判断四个文件的大小,请问要怎么写了。
解决方案 »
- c# vs2005 用axWebBrowser控件做一个浏览器,新打开的链接
- 无法找到 PInvoke DLL“dbnetlib.dll”。
- C#连接Access数据库,在IIS中报未知错误,但用VS自带的服务器正常。
- 如何使用.net C# 编程给pdf文件加密
- vs2005 在 InitializeComponent() 用 const 变量赋值 的问题。 答对一定加分!
- startinfo.Arguments如何实现多条命令
- 请推荐几本学习VS的好书
- 远程对象访问数据库的问题!急!急!急!!
- xml问题,求助!!!
- Entity Framework 5.0 调用存储过程 返回值为什么是int类型
- 关于类名和实例名的命名问题
- 本机器COM1与COM3是否可以通信问题?
{
if (string.IsNullOrEmpty(str) || !File.Exists(str))
{
throw new ArgumentException("Invalid path specified!");
} FileInfo info = new FileInfo(str);
return info.Length == length;
} // demo code
string file1 = "Start.exe";
int len1 = 4391424;
bool isFile1OK = IsFileOk(file1, len1);
System.IO.FileInfo info = new System.IO.FileInfo("Start.exe");
System.IO.FileInfo info1 = new System.IO.FileInf("data\\texts_us.tbl");
System.IO.FileInfo info2 = new System.IO.FileInfo("Start1.exe");
System.IO.FileInfo info3 = new System.IO.FileInf("data\\texts_us1.tbl");
if (info.Length.ToString() == "4391424" && info1.Length.ToString() == "46371" && info2.Length.ToString() == "45615" && info3.Length.ToString() == "45147")
{ }
else
{ }
using System.Collections.Generic;
using System.Text;
using System.Collections;
using System.IO;namespace 通过IComparable是类型可排序
{
public class CompareFileSize : IComparer
{
//通过重载 Compare 可以定制比较方式. 此处.为比较文件大小.顺序排列为从小到大..
//(如果想从大到小显示只需将return 1 ,-1 调换下就可以)
public int Compare(object o1, object o2)
{
if (!(o1 is FileInfo) || !(o2 is FileInfo))
{
throw new Exception(" Is Not The FileInfo Object !");
}
if (((FileInfo)o1).Length == ((FileInfo)o2).Length)
{
return 0;
}
else if (((FileInfo)o1).Length > ((FileInfo)o2).Length)
return 1;
else
return -1;
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Collections;
using System.IO;namespace 通过IComparable是类型可排序
{
class Program
{
static void Main(string[] args)
{
// 用实现的接口比较大小,方便且不限制比较的数目.
CompareFileSize comparefilesize = new CompareFileSize ();
FileInfo[] fileinfo = new FileInfo[4];
fileinfo[0] = new FileInfo (@"d:\test01.txt") ;
fileinfo[1] = new FileInfo (@"d:\test02.txt") ;
fileinfo[2] = new FileInfo (@"d:\test03.txt") ;
fileinfo[3] = new FileInfo (@"d:\test04.txt"); Array.Sort(fileinfo,comparefilesize);
foreach (FileInfo i in fileinfo)
{
Console.WriteLine(i.Name.ToString());
}
Console.ReadLine();
}
}
}