我的源文件在D:\file下,我想实时拷贝文件到E:\file1下,每30-50分钟有一个文件生成到D:\file下,文件名就是 年_月_日_时_分+fi.jpg,例如今天11:40来的文件文件名是2010_08_04_11_40.jpg,12:40来的文件文件名是2010_08_04_12_40.jpg,现在如何做到,只要有文件生成到D:\file下,就能实时拷贝到E:\file1下,并把文件名改为年_月_日_时+4_分+fi.jpg(例如今天11:40来的文件文件名拷贝过来小时上加4个小时,变为2010_08_04_15_40.jpg,例如今天12:40来的文件文件名拷贝过来小时上加4个小时,变为2010_08_04_16_40.jpg)
File.Copy(@"d:\file\a.jpg", string.Format(@"e:\file\{0}.jpg", dateTime.Now.Tostring("yyyy_MM_dd_H_mm_ss")))
File.Copy(@"d:\file\a.jpg", string.Format(@"e:\file\{0}.jpg", dateTime.Now.AddHours(4).Tostring("yyyy_MM_dd_H_mm_ss")))
C#追加文件
StreamWriter sw = File.AppendText(Server.MapPath(".")+"\\myText.txt");
sw.WriteLine("追逐理想");
sw.WriteLine("kzlll");
sw.WriteLine(".NET笔记");
sw.Flush();
sw.Close();
C#拷贝文件
string OrignFile,NewFile;
OrignFile = Server.MapPath(".")+"\\myText.txt";
NewFile = Server.MapPath(".")+"\\myTextCopy.txt";
File.Copy(OrignFile,NewFile,true);
C#删除文件
string delFile = Server.MapPath(".")+"\\myTextCopy.txt";
File.Delete(delFile);
C#移动文件
string OrignFile,NewFile;
OrignFile = Server.MapPath(".")+"\\myText.txt";
NewFile = Server.MapPath(".")+"\\myTextCopy.txt";
File.Move(OrignFile,NewFile);
那么就要根据时间来遍历d盘file文件夹下所有文件的文件名了。