如何多次将文件从一个位置移动/复制到另一个位置? [英] How to move/copy a file from one location to another multiple times?

查看:232
本文介绍了如何多次将文件从一个位置移动/复制到另一个位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

就像我们可以通过在计时器控件事件中编写messagebox语句来继续显示消息。同样的方式我想继续将文件(文本文件)复制到另一个位置,直到用户没有停止计时器。我可以成功复制/移动文件,但我想继续复制。它是c#.net中的一个Windows应用程序。

Like we can keep displaying a message by writing a messagebox statement in a timer control event. Same way i want to keep copying a file(text file) to another location until a timer is not stopped by the user. I can copy/move file successfully but i want to continue copying. Its a windows application in c#.net.

推荐答案

嘿,

你可以试试这样的东西:



int i = 0;

var timer = new Timer();

timer.Interval = 500;

timer.Start();

timer.Tick + = delegate {

//创建一个简单的.txt文件

System.IO .File.Create(/ * sample path + filename * / @c:\ myfile+ i.ToString(); +。txt);

//将文本追加到.txt文件。第一个参数:file,你追加文本的地方,

//第二个参数:定义你要附加的文本

System.IO.File.AppendAllText(@c :\ myfile+ i.ToString();,

File.ReadAllText(/ * sample path + filename * / @c:\ file_you_want_to_copy);



//下次增加整数以创建另一个文件。

i ++;

};
Hey,
you could try something like this:

int i = 0;
var timer = new Timer();
timer.Interval = 500;
timer.Start();
timer.Tick += delegate {
//Creates a simple .txt file
System.IO.File.Create(/*sample path+filename*/ @ "c:\myfile" + i.ToString();+".txt");
//appends the text to the .txt file. first parameter: file, where you append the text,
//second parameter: define which text you want to append
System.IO.File.AppendAllText(@ "c:\myfile" + i.ToString();,
File.ReadAllText(/*sample path+filename*/@"c:\file_you_want_to_copy");

//increase the integer to create another file next time.
i++;
};


这篇关于如何多次将文件从一个位置移动/复制到另一个位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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