首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

c#如何样把一个文件移动到指定文件夹下面(,搞定就给分)

2012-01-24 
c#怎么样把一个文件移动到指定文件夹下面(在线等,搞定就给分)c#怎么样把一个文件移动到指定文件夹下面比如

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");

热点排行