日期:2014-05-18  浏览次数:20875 次

c#怎么样把一个文件移动到指定文件夹下面(在线等,搞定就给分)
c#怎么样把一个文件移动到指定文件夹下面 比如,有文件 1.txt,2.txt 都要移动到 d:\h这个文件夹下
怎么做? 说清楚些 谢谢

------解决方案--------------------
System.IO.File.Move(...)
------解决方案--------------------
string path = @"1.txt";
string path2 = @"d:\h\1.txt";

if (!File.Exists(path)) 
{
using (FileStream fs = File.Create(path)) {}
}
if (File.Exists(path2))
{File.Delete(path2);}

File.Move(path, path2);
------解决方案--------------------
你可以写一个这样的函数:
void Move(string filename, string folder)
{
string fullname = folder + "\\" + filename;
if(File.Exist(fullname)) File.Delete(fullname);
File.Move(filename, fullname);
}
然后就可以调用这个函数来实现移动了,比如:
Move("1.txt", "d:\\h");
Move("2.txt", "d:\\h");