我需要寫一個程式,要對15個不同路徑下的目錄進行操作,需要將這些目錄中的文件(文件是隨機產生)COPY到相對應的15個目錄下。
我想通過Thread來實現(環境是vs2003),代碼如下:
Thread a = new Thread(new ThreadStart(1));
a.IsBackground=true;
a.Start();
Thread b = new Thread(new ThreadStart(2));
b.IsBackground=true;
b.Start();
.......... 直到15為止............
調用代碼如下:
while (true)
{
System.Threading.Thread.Sleep(10000);
System.IO.DirectoryInfo _DI2 = new DirectoryInfo(@"d:\3");
FileInfo[] _files2 = _DI2.GetFiles();
foreach(FileInfo _file2 in _files2)
{
string filenamec=_file2.Name;
string pathc=@"d:\3\"+filenamec;
if(File.Exists(pathc))
{
try
{
_file2.CopyTo(@"e:\4\" + _file2.Name,true);
_file2.CopyTo(@"e:\5\" + _file2.Name,true);
File.Delete(@"d:\3\"+_file2.Name); this.listBox1.Items.Add("Thie file copy OK:" + _file2.Name);
}
catch (Exception ex)
{
string errorinfo2=ex.Message;
this.listBox1.Items.Add("Thie file copy Fail:" + _file2.Name + errorinfo2); string errorfile2=_file2.Name;
string path4 = @"d:\3\"+_file2.Name;
string path5 = @"d:\4\"+_file2.Name;
if (File.Exists(path5))
File.Delete(path5);
File.Move(path4,path5); }} } } 有什麼辦法可以實現我的目的,又來將效率提高呢?
我想通過Thread來實現(環境是vs2003),代碼如下:
Thread a = new Thread(new ThreadStart(1));
a.IsBackground=true;
a.Start();
Thread b = new Thread(new ThreadStart(2));
b.IsBackground=true;
b.Start();
.......... 直到15為止............
調用代碼如下:
while (true)
{
System.Threading.Thread.Sleep(10000);
System.IO.DirectoryInfo _DI2 = new DirectoryInfo(@"d:\3");
FileInfo[] _files2 = _DI2.GetFiles();
foreach(FileInfo _file2 in _files2)
{
string filenamec=_file2.Name;
string pathc=@"d:\3\"+filenamec;
if(File.Exists(pathc))
{
try
{
_file2.CopyTo(@"e:\4\" + _file2.Name,true);
_file2.CopyTo(@"e:\5\" + _file2.Name,true);
File.Delete(@"d:\3\"+_file2.Name); this.listBox1.Items.Add("Thie file copy OK:" + _file2.Name);
}
catch (Exception ex)
{
string errorinfo2=ex.Message;
this.listBox1.Items.Add("Thie file copy Fail:" + _file2.Name + errorinfo2); string errorfile2=_file2.Name;
string path4 = @"d:\3\"+_file2.Name;
string path5 = @"d:\4\"+_file2.Name;
if (File.Exists(path5))
File.Delete(path5);
File.Move(path4,path5); }} } } 有什麼辦法可以實現我的目的,又來將效率提高呢?
解决方案 »
- C#中如何让文本框中纯在固定字符,而且不影响内容输入,如货币符号
- C# WinForm显示AutoCad文件
- vb.net 或 c#.net 如何执行VBS脚本
- 关于数据库远程本地的问题,耽误大家时间了
- bootstrapper packages什么意思?
- DataTable.LoadDataRow 方法 (Object[], Boolean) 是如何更新特定行的
- 用C#写一个工具条,如何使其它打开的窗口最大化后,上边框只能到该工具条下边
- C#怎么向水晶报表中传参数? 水晶报表中怎么对应传过来的参数?
- 在异步套接字中,如何判断客户端已经关闭或断开?
- 新手的问题,关于使用注册表,请朋友们帮我
- 怎样在窗体程序中修改数据库内容后同时数据库更新
- C# 如何取得 其他正在运行的程序 的数据
有沒有更好的辦法呢?
還有就是哪個目錄路徑是死的,不能更改.....