我最近在做一个项目(C#,winform),要实现一个功能就是从客户端获取一段字符(文件夹名),然后与服务器上面的文件夹名称进行匹配查找,如果服务器上面有该文件夹不做任何处理,如果没有,则创建该文件夹!
问题是现在服务器上面有大批量的文件夹,而且还不断产生,我想用循环查找匹配,但是这样是不是效率太低了,所以请大家
帮忙看有没有什么好的思路方法??只说逻辑即可
问题是现在服务器上面有大批量的文件夹,而且还不断产生,我想用循环查找匹配,但是这样是不是效率太低了,所以请大家
帮忙看有没有什么好的思路方法??只说逻辑即可
解决方案 »
- C#控制台程序,如何实时监测有硬件输入?
- 使用using,的时候如果出现异常的话那么using内部的比如myConnection 资源会被释放掉吗,就算我写dispose
- 如何把六个变量随机组合
- 高分求教:TextBox添加的Click事件为什么不能在WinCE下运行?
- 为什么输出的只有5
- 孟大哥,过来帮帮小弟吧!在C#中怎样把“备注型”字段中存储的图片生成出文件来?
- ie已经运行。。。,如何让程序向ie发送消息。跳转到指定网站。。?
- 取变量的值的问题!
- 高手进来捡分
- 关于数组的疑问,给我讲讲。。。
- 会什么点了添加,没有反应,数据到是更新了,但是页面还不行
- 请教用vs2008 打包程序成setup.msi反安装的问题
if (!dir.Exists)
{
dir.Create();
}code]
if (!dir.Exists)
{
dir.Create();
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;namespace WindowsApplication244
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent(); FileSystemWatcher FSW = new FileSystemWatcher();
FSW.Path = @"c:\";
FSW.NotifyFilter = NotifyFilters.DirectoryName;
FSW.Created += new FileSystemEventHandler(FSW_Created);
FSW.Deleted += new FileSystemEventHandler(FSW_Deleted);
FSW.Renamed += new RenamedEventHandler(FSW_Renamed); FSW.EnableRaisingEvents = true;
} void FSW_Renamed(object sender, RenamedEventArgs e)
{
String S = File.ReadAllText(@"c:\save.txt"); S = S.Replace(e.OldFullPath + Environment.NewLine
, e.FullPath + Environment.NewLine);
File.WriteAllText(@"c:\save.txt", S); MessageBox.Show("当前C盘根目录下所有一级子目录: " + S);
} void FSW_Deleted(object sender, FileSystemEventArgs e)
{
if (!File.Exists(@"c:\save.txt"))
return; String S = File.ReadAllText(@"c:\save.txt"); S = S.Replace(e.FullPath + Environment.NewLine, String.Empty);
File.WriteAllText(@"c:\save.txt", S); MessageBox.Show("当前C盘根目录下所有一级子目录: " + S);
} void FSW_Created(object sender, FileSystemEventArgs e)
{
String S = String.Empty; if (!File.Exists(@"c:\save.txt"))
File.Create(@"c:\save.txt").Close();
else
S = File.ReadAllText(@"c:\save.txt"); S += e.FullPath + Environment.NewLine;
File.WriteAllText(@"c:\save.txt", S); MessageBox.Show("当前C盘根目录下所有一级子目录: " + S);
}
}
}
又是遍历,又有字符串匹配,所以,比较直接这个方案。
而且,个人认为,这个索引如果不方便放到内存里的话,用数据库应该比较好,不需要自己写算法,用SQL语句就可以,速度也比较有保障。只是,需要注意一下与实际存储情况的同步。
虽然可以用FOR循环,但是由于文件夹太多,效率会不会太低???
2.客户端查询时: 到数据库中查询(建索引),这样速度会非常快,而且不用担心数据量大小,几千万个数据量也是没有问题的